This repository has been archived by the owner on Jun 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): add support for rewriting
require
calls
Only works for **top level** calls. Need to implement walking the whole ES AST tree for that
- Loading branch information
1 parent
7f37921
commit d1ea076
Showing
15 changed files
with
140 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import RequireCallExpression from '@es/RequireCallExpression'; | ||
|
||
import Declaration, { IOptions as IDeclarationOptions } from '@es/Declaration'; | ||
|
||
export type Interface = RequireCallExpression; | ||
|
||
export type IOptions = IDeclarationOptions<Interface>; | ||
|
||
export default class Require extends Declaration<Interface> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Identifier, SimpleCallExpression, SimpleLiteral } from 'estree'; | ||
|
||
// tslint:disable-next-line:interface-name | ||
export default interface RequireCallExpression extends SimpleCallExpression { | ||
callee: Identifier; | ||
arguments: [ SimpleLiteral ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ExportNamedDeclaration, Node } from 'estree'; | ||
|
||
export default function isExportNamedDeclaration(data: Node | null | undefined): data is ExportNamedDeclaration { | ||
return data !== null && | ||
data !== undefined && | ||
(data.type === 'ExportAllDeclaration' | ||
|| (data.type === 'ExportNamedDeclaration' && data.source !== null)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Identifier, Node } from 'estree'; | ||
|
||
export default function isIdentifier(data: Node | null | undefined): data is Identifier { | ||
return data !== null && data !== undefined && data.type === 'Identifier'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ImportDeclaration, Node } from 'estree'; | ||
|
||
export default function isImportDeclaration(data: Node | null | undefined): data is ImportDeclaration { | ||
return data !== null && data !== undefined && data.type === 'ImportDeclaration'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import isIdentifier from '@es/isIdentifier'; | ||
import isSimpleCallExpression from '@es/isSimpleCallExpression'; | ||
import isSimpleLiteral from '@es/isSimpleLiteral'; | ||
import RequireCallExpression from '@es/RequireCallExpression'; | ||
import { Node } from 'estree'; | ||
|
||
export default function isRequireCallExpression(data: Node | undefined | null): data is RequireCallExpression { | ||
return data !== null && | ||
data !== undefined && | ||
isSimpleCallExpression(data) && | ||
isIdentifier(data.callee) && | ||
data.callee.name === 'require' && | ||
data.arguments.length === 1 && | ||
isSimpleLiteral(data.arguments[0]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Node, SimpleCallExpression } from 'estree'; | ||
|
||
export default function isSimpleCallExpression(data: Node | undefined | null): data is SimpleCallExpression { | ||
return data !== null && data !== undefined && data.type === 'CallExpression'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Node, SimpleLiteral } from 'estree'; | ||
|
||
export default function isIdentifier(data: Node | null | undefined): data is SimpleLiteral { | ||
return data !== null && data !== undefined && data.type === 'Literal'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Node, VariableDeclaration } from 'estree'; | ||
|
||
export default function isVariableDeclaration(data: Node | null | undefined): data is VariableDeclaration { | ||
return data !== null && data !== undefined && data.type === 'VariableDeclaration'; | ||
} |