WIP - add extractor, generate snippet_data

This commit is contained in:
Stefan Fejes
2019-08-20 15:52:05 +02:00
parent 88084d3d30
commit cc8f1d8a7a
37396 changed files with 4588842 additions and 133 deletions

View File

@ -0,0 +1,14 @@
import SpreadElement from './SpreadElement';
import { SomeReturnExpressionCallback } from './shared/Expression';
import { ExpressionNode, NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
import CallOptions from '../CallOptions';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { ObjectPath } from '../values';
export default class ArrayExpression extends NodeBase {
type: NodeType.ArrayExpression;
elements: (ExpressionNode | SpreadElement | null)[];
hasEffectsWhenAccessedAtPath(path: ObjectPath): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,14 @@
import { ObjectPath } from '../values';
import Scope from '../scopes/Scope';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { PatternNode } from './shared/Pattern';
import { ExpressionEntity } from './shared/Expression';
import { NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
export default class ArrayPattern extends NodeBase implements PatternNode {
type: NodeType.ArrayPattern;
elements: (PatternNode | null)[];
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
initialiseAndDeclare(parentScope: Scope, kind: string, _init: ExpressionEntity | null): void;
}

View File

@ -0,0 +1,25 @@
import Scope from '../scopes/Scope';
import ReturnValueScope from '../scopes/ReturnValueScope';
import BlockStatement from './BlockStatement';
import CallOptions from '../CallOptions';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from './shared/Expression';
import { PatternNode } from './shared/Pattern';
import { NodeType } from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
import { ObjectPath } from '../values';
export default class ArrowFunctionExpression extends NodeBase {
type: NodeType.ArrowFunctionExpression;
body: BlockStatement | ExpressionNode;
params: PatternNode[];
scope: ReturnValueScope;
bindNode(): void;
forEachReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, callback: ForEachReturnExpressionCallback, options: ExecutionPathOptions): void;
hasEffects(_options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, _callOptions: CallOptions, options: ExecutionPathOptions): boolean;
initialiseChildren(): void;
initialiseScope(parentScope: Scope): void;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,13 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import { PatternNode } from './shared/Pattern';
import { ExpressionNode, NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
import { ObjectPath } from '../values';
export default class AssignmentExpression extends NodeBase {
type: NodeType.AssignmentExpression;
left: PatternNode | ExpressionNode;
right: ExpressionNode;
bindNode(): void;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,16 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import Scope from '../scopes/Scope';
import { PatternNode } from './shared/Pattern';
import { ExpressionEntity } from './shared/Expression';
import { ExpressionNode, NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
import { ObjectPath } from '../values';
export default class AssignmentPattern extends NodeBase implements PatternNode {
type: NodeType.AssignmentPattern;
left: PatternNode;
right: ExpressionNode;
bindNode(): void;
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
initialiseAndDeclare(parentScope: Scope, kind: string, init: ExpressionEntity | null): void;
}

View File

@ -0,0 +1,10 @@
import { PatternNode } from './shared/Pattern';
import { ExpressionNode } from './shared/Node';
import { NodeType } from './NodeType';
export default interface AssignmentProperty extends PatternNode {
type: NodeType.Property;
value: PatternNode;
key: ExpressionNode;
kind: 'init';
method: false;
}

View File

@ -0,0 +1,8 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeType } from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
export default class AwaitExpression extends NodeBase {
type: NodeType.AwaitExpression;
argument: ExpressionNode;
hasEffects(options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,13 @@
import { ObjectPath } from '../values';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeType } from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
export declare type BinaryOperator = '==' | '!=' | '===' | '!==' | '<' | '<=' | '>' | '>=' | '<<' | '>>' | '>>>' | '+' | '-' | '*' | '/' | '%' | ' |' | '^' | '&' | '**' | 'in' | 'instanceof';
export default class BinaryExpression extends NodeBase {
type: NodeType.BinaryExpression;
left: ExpressionNode;
right: ExpressionNode;
operator: BinaryOperator;
getValue(): any;
hasEffectsWhenAccessedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,19 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import Scope from '../scopes/Scope';
import MagicString from 'magic-string';
import { Node, StatementBase, StatementNode } from './shared/Node';
import { NodeType } from './NodeType';
import { RenderOptions } from '../../utils/renderHelpers';
export declare function isBlockStatement(node: Node): node is BlockStatement;
export default class BlockStatement extends StatementBase {
type: NodeType.BlockStatement;
scope: Scope;
body: StatementNode[];
bindImplicitReturnExpressionToScope(): void;
hasEffects(options: ExecutionPathOptions): boolean;
includeInBundle(): boolean;
initialiseAndReplaceScope(scope: Scope): void;
initialiseChildren(_parentScope: Scope): void;
initialiseScope(parentScope: Scope): void;
render(code: MagicString, options: RenderOptions): void;
}

View File

@ -0,0 +1,9 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import Identifier from './Identifier';
import { NodeType } from './NodeType';
import { StatementBase } from './shared/Node';
export default class BreakStatement extends StatementBase {
type: NodeType.BreakStatement;
label: Identifier | null;
hasEffects(options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,22 @@
import CallOptions from '../CallOptions';
import ExecutionPathOptions from '../ExecutionPathOptions';
import SpreadElement from './SpreadElement';
import { ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from './shared/Expression';
import { NodeType } from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
import { ObjectPath } from '../values';
export default class CallExpression extends NodeBase {
type: NodeType.CallExpression;
callee: ExpressionNode;
arguments: (ExpressionNode | SpreadElement)[];
private _callOptions;
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
bindNode(): void;
forEachReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, callback: ForEachReturnExpressionCallback, options: ExecutionPathOptions): void;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
initialiseNode(): void;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,14 @@
import { NodeBase } from './shared/Node';
import CatchScope from '../scopes/CatchScope';
import BlockStatement from './BlockStatement';
import Scope from '../scopes/Scope';
import { PatternNode } from './shared/Pattern';
import { NodeType } from './NodeType';
export default class CatchClause extends NodeBase {
type: NodeType.CatchClause;
param: PatternNode;
body: BlockStatement;
scope: CatchScope;
initialiseChildren(): void;
initialiseScope(parentScope: Scope): void;
}

View File

@ -0,0 +1,13 @@
import { NodeBase } from './shared/Node';
import ExecutionPathOptions from '../ExecutionPathOptions';
import CallOptions from '../CallOptions';
import MethodDefinition from './MethodDefinition';
import { NodeType } from './NodeType';
import { ObjectPath } from '../values';
export default class ClassBody extends NodeBase {
type: NodeType.ClassBody;
body: MethodDefinition[];
classConstructor: MethodDefinition | null;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
initialiseNode(): void;
}

View File

@ -0,0 +1,14 @@
import ClassNode from './shared/ClassNode';
import Scope from '../scopes/Scope';
import Identifier from './Identifier';
import MagicString from 'magic-string';
import { NodeType } from './NodeType';
import { Node } from './shared/Node';
import { RenderOptions } from '../../utils/renderHelpers';
export declare function isClassDeclaration(node: Node): node is ClassDeclaration;
export default class ClassDeclaration extends ClassNode {
type: NodeType.ClassDeclaration;
id: Identifier;
initialiseChildren(parentScope: Scope): void;
render(code: MagicString, options: RenderOptions): void;
}

View File

@ -0,0 +1,10 @@
import ClassNode from './shared/ClassNode';
import Scope from '../scopes/Scope';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeType } from './NodeType';
import { ObjectPath } from '../values';
export default class ClassExpression extends ClassNode {
type: NodeType.ClassExpression;
initialiseChildren(parentScope: Scope): void;
reassignPath(_path: ObjectPath, _options: ExecutionPathOptions): void;
}

View File

@ -0,0 +1,26 @@
import { ObjectPath } from '../values';
import ExecutionPathOptions from '../ExecutionPathOptions';
import CallOptions from '../CallOptions';
import MagicString from 'magic-string';
import { ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from './shared/Expression';
import { NodeType } from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
export default class ConditionalExpression extends NodeBase {
type: NodeType.ConditionalExpression;
test: ExpressionNode;
alternate: ExpressionNode;
consequent: ExpressionNode;
forEachReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, callback: ForEachReturnExpressionCallback, options: ExecutionPathOptions): void;
getValue(): any;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
includeInBundle(): boolean;
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
render(code: MagicString, options: RenderOptions, {renderedParentType, isCalleeOfRenderedParent}?: NodeRenderOptions): void;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
private forEachRelevantBranch(callback);
private someRelevantBranch(predicateFunction);
}

View File

@ -0,0 +1,9 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import { ExpressionNode, StatementNode, StatementBase } from './shared/Node';
import { NodeType } from './NodeType';
export default class DoWhileStatement extends StatementBase {
type: NodeType.DoWhileStatement;
body: StatementNode;
test: ExpressionNode;
hasEffects(options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,8 @@
import MagicString from 'magic-string';
import { NodeType } from './NodeType';
import { StatementBase } from './shared/Node';
import { RenderOptions } from '../../utils/renderHelpers';
export default class EmptyStatement extends StatementBase {
type: NodeType.EmptyStatement;
render(code: MagicString, _options: RenderOptions): void;
}

View File

@ -0,0 +1,12 @@
import { NodeBase } from './shared/Node';
import Literal from './Literal';
import MagicString from 'magic-string';
import { NodeType } from './NodeType';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
export default class ExportAllDeclaration extends NodeBase {
type: NodeType.ExportAllDeclaration;
source: Literal<string>;
isExportDeclaration: true;
needsBoundaries: true;
render(code: MagicString, _options: RenderOptions, {start, end}?: NodeRenderOptions): void;
}

View File

@ -0,0 +1,20 @@
import { ExpressionNode, NodeBase } from './shared/Node';
import ExportDefaultVariable from '../variables/ExportDefaultVariable';
import ClassDeclaration from './ClassDeclaration';
import FunctionDeclaration from './FunctionDeclaration';
import MagicString from 'magic-string';
import { NodeType } from './NodeType';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
export default class ExportDefaultDeclaration extends NodeBase {
type: NodeType.ExportDefaultDeclaration;
declaration: FunctionDeclaration | ClassDeclaration | ExpressionNode;
needsBoundaries: true;
isExportDeclaration: true;
variable: ExportDefaultVariable;
private declarationName;
bindNode(): void;
initialiseNode(): void;
render(code: MagicString, options: RenderOptions, {start, end}?: NodeRenderOptions): void;
private renderNamedDeclaration(code, declarationStart, declarationKeyword, needsId, options);
private renderVariableDeclaration(code, declarationStart, options);
}

View File

@ -0,0 +1,21 @@
import { NodeBase } from './shared/Node';
import ExecutionPathOptions from '../ExecutionPathOptions';
import Literal from './Literal';
import MagicString from 'magic-string';
import ExportSpecifier from './ExportSpecifier';
import FunctionDeclaration from './FunctionDeclaration';
import ClassDeclaration from './ClassDeclaration';
import VariableDeclaration from './VariableDeclaration';
import { NodeType } from './NodeType';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
export default class ExportNamedDeclaration extends NodeBase {
type: NodeType.ExportNamedDeclaration;
declaration: FunctionDeclaration | ClassDeclaration | VariableDeclaration | null;
specifiers: ExportSpecifier[];
source: Literal<string> | null;
needsBoundaries: true;
isExportDeclaration: true;
bindChildren(): void;
hasEffects(options: ExecutionPathOptions): boolean;
render(code: MagicString, options: RenderOptions, {start, end}?: NodeRenderOptions): void;
}

View File

@ -0,0 +1,8 @@
import { Node } from './shared/Node';
import Identifier from './Identifier';
import { NodeType } from './NodeType';
export default interface ExportSpecifier extends Node {
type: NodeType.ExportSpecifier;
local: Identifier;
exported: Identifier;
}

View File

@ -0,0 +1,10 @@
import MagicString from 'magic-string';
import Scope from '../scopes/Scope';
import { StatementBase } from './shared/Node';
import { RenderOptions } from '../../utils/renderHelpers';
export default class ExpressionStatement extends StatementBase {
directive?: string;
initialiseNode(_parentScope: Scope): void;
shouldBeIncluded(): boolean;
render(code: MagicString, options: RenderOptions): void;
}

View File

@ -0,0 +1,20 @@
import VariableDeclaration from './VariableDeclaration';
import Scope from '../scopes/Scope';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { PatternNode } from './shared/Pattern';
import { NodeType } from './NodeType';
import { ExpressionNode, Node, StatementBase, StatementNode } from './shared/Node';
import MagicString from 'magic-string';
import { RenderOptions } from '../../utils/renderHelpers';
export declare function isForInStatement(node: Node): node is ForInStatement;
export default class ForInStatement extends StatementBase {
type: NodeType.ForInStatement;
left: VariableDeclaration | PatternNode;
right: ExpressionNode;
body: StatementNode;
hasEffects(options: ExecutionPathOptions): boolean;
initialiseChildren(): void;
includeInBundle(): boolean;
initialiseScope(parentScope: Scope): void;
render(code: MagicString, options: RenderOptions): void;
}

View File

@ -0,0 +1,21 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import VariableDeclaration from './VariableDeclaration';
import Scope from '../scopes/Scope';
import { PatternNode } from './shared/Pattern';
import { NodeType } from './NodeType';
import { ExpressionNode, Node, StatementBase, StatementNode } from './shared/Node';
import MagicString from 'magic-string';
import { RenderOptions } from '../../utils/renderHelpers';
export declare function isForOfStatement(node: Node): node is ForOfStatement;
export default class ForOfStatement extends StatementBase {
type: NodeType.ForOfStatement;
left: VariableDeclaration | PatternNode;
right: ExpressionNode;
body: StatementNode;
bindNode(): void;
hasEffects(options: ExecutionPathOptions): boolean;
includeInBundle(): boolean;
initialiseChildren(): void;
initialiseScope(parentScope: Scope): void;
render(code: MagicString, options: RenderOptions): void;
}

View File

@ -0,0 +1,19 @@
import VariableDeclaration from './VariableDeclaration';
import ExecutionPathOptions from '../ExecutionPathOptions';
import Scope from '../scopes/Scope';
import { NodeType } from './NodeType';
import { ExpressionNode, Node, StatementBase, StatementNode } from './shared/Node';
import MagicString from 'magic-string';
import { RenderOptions } from '../../utils/renderHelpers';
export declare function isForStatement(node: Node): node is ForStatement;
export default class ForStatement extends StatementBase {
type: NodeType.ForStatement;
init: VariableDeclaration | ExpressionNode | null;
test: ExpressionNode | null;
update: ExpressionNode | null;
body: StatementNode;
hasEffects(options: ExecutionPathOptions): boolean;
initialiseChildren(): void;
initialiseScope(parentScope: Scope): void;
render(code: MagicString, options: RenderOptions): void;
}

View File

@ -0,0 +1,9 @@
import FunctionNode from './shared/FunctionNode';
import Scope from '../scopes/Scope';
import { NodeType } from './NodeType';
import { Node } from './shared/Node';
export declare function isFunctionDeclaration(node: Node): node is FunctionDeclaration;
export default class FunctionDeclaration extends FunctionNode {
type: NodeType.FunctionDeclaration;
initialiseChildren(parentScope: Scope): void;
}

View File

@ -0,0 +1,6 @@
import FunctionNode from './shared/FunctionNode';
import { NodeType } from './NodeType';
export default class FunctionExpression extends FunctionNode {
type: NodeType.FunctionExpression;
initialiseChildren(): void;
}

View File

@ -0,0 +1,29 @@
import { Node, NodeBase } from './shared/Node';
import { ObjectPath } from '../values';
import Scope from '../scopes/Scope';
import ExecutionPathOptions from '../ExecutionPathOptions';
import Variable from '../variables/Variable';
import CallOptions from '../CallOptions';
import MagicString from 'magic-string';
import { ExpressionEntity, ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from './shared/Expression';
import { NodeType } from './NodeType';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
export declare function isIdentifier(node: Node): node is Identifier;
export default class Identifier extends NodeBase {
type: NodeType.Identifier;
name: string;
variable: Variable;
private isBound;
bindNode(): void;
forEachReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, callback: ForEachReturnExpressionCallback, options: ExecutionPathOptions): void;
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
includeInBundle(): boolean;
initialiseAndDeclare(parentScope: Scope, kind: string, init: ExpressionEntity | null): void;
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
private disallowImportReassignment();
renderSystemBindingUpdate(code: MagicString, name: string): void;
render(code: MagicString, options: RenderOptions, {renderedParentType, isCalleeOfRenderedParent}?: NodeRenderOptions): void;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,17 @@
import Scope from '../scopes/Scope';
import { ExpressionNode, StatementBase, StatementNode } from './shared/Node';
import MagicString from 'magic-string';
import { NodeType } from './NodeType';
import { RenderOptions } from '../../utils/renderHelpers';
export default class IfStatement extends StatementBase {
type: NodeType.IfStatement;
test: ExpressionNode;
consequent: StatementNode;
alternate: StatementNode | null;
private testValue;
private hoistedVars?;
initialiseChildren(parentScope: Scope): void;
initialiseNode(): void;
render(code: MagicString, options: RenderOptions): void;
shouldBeIncluded(): boolean;
}

16
node_modules/rollup/dist/typings/ast/nodes/Import.d.ts generated vendored Normal file
View File

@ -0,0 +1,16 @@
import CallExpression from './CallExpression';
import { NodeType } from './NodeType';
import { NodeBase } from './shared/Node';
import MagicString from 'magic-string';
import { RenderOptions } from '../../utils/renderHelpers';
export default class Import extends NodeBase {
type: NodeType.Import;
parent: CallExpression;
constructor();
private resolutionNamespace;
private resolutionInterop;
private rendered;
setResolution(interop: boolean, namespace?: string): void;
renderFinalResolution(code: MagicString, resolution: string): void;
render(code: MagicString, options: RenderOptions): void;
}

View File

@ -0,0 +1,17 @@
import { NodeBase } from './shared/Node';
import Literal from './Literal';
import ImportSpecifier from './ImportSpecifier';
import ImportDefaultSpecifier from './ImportDefaultSpecifier';
import ImportNamespaceSpecifier from './ImportNamespaceSpecifier';
import MagicString from 'magic-string';
import { NodeType } from './NodeType';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
export default class ImportDeclaration extends NodeBase {
type: NodeType.ImportDeclaration;
specifiers: (ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier)[];
source: Literal<string>;
isImportDeclaration: true;
needsBoundaries: true;
bindChildren(): void;
render(code: MagicString, _options: RenderOptions, {start, end}?: NodeRenderOptions): void;
}

View File

@ -0,0 +1,7 @@
import Identifier from './Identifier';
import { Node } from './shared/Node';
import { NodeType } from './NodeType';
export default interface ImportDefaultSpecifier extends Node {
type: NodeType.ImportDefaultSpecifier;
local: Identifier;
}

View File

@ -0,0 +1,7 @@
import Identifier from './Identifier';
import { Node } from './shared/Node';
import { NodeType } from './NodeType';
export default interface ImportNamespaceSpecifier extends Node {
type: NodeType.ImportNamespaceSpecifier;
local: Identifier;
}

View File

@ -0,0 +1,8 @@
import Identifier from './Identifier';
import { Node } from './shared/Node';
import { NodeType } from './NodeType';
export default interface ImportSpecifier extends Node {
type: NodeType.ImportSpecifier;
local: Identifier;
imported: Identifier;
}

View File

@ -0,0 +1,10 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import Identifier from './Identifier';
import { NodeType } from './NodeType';
import { StatementBase, StatementNode } from './shared/Node';
export default class LabeledStatement extends StatementBase {
type: NodeType.LabeledStatement;
label: Identifier;
body: StatementNode;
hasEffects(options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,22 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import MagicString from 'magic-string';
import { SomeReturnExpressionCallback } from './shared/Expression';
import { Node, NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
import CallOptions from '../CallOptions';
import { ObjectPath } from '../values';
import { RenderOptions } from '../../utils/renderHelpers';
export declare type LiteralValueTypes = string | boolean | null | number | RegExp;
export declare function isLiteral(node: Node): node is Literal;
export default class Literal<T = LiteralValueTypes> extends NodeBase {
type: NodeType.Literal;
value: T;
private members;
getValue(): T;
hasEffectsWhenAccessedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
initialiseNode(): void;
render(code: MagicString, _options: RenderOptions): void;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,27 @@
import { ObjectPath } from '../values';
import CallOptions from '../CallOptions';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from './shared/Expression';
import { NodeType } from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import MagicString from 'magic-string';
export declare type LogicalOperator = '||' | '&&';
export default class LogicalExpression extends NodeBase {
type: NodeType.LogicalExpression;
operator: LogicalOperator;
left: ExpressionNode;
right: ExpressionNode;
forEachReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, callback: ForEachReturnExpressionCallback, options: ExecutionPathOptions): void;
getValue(): any;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
includeInBundle(): boolean;
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
render(code: MagicString, options: RenderOptions, {renderedParentType, isCalleeOfRenderedParent}?: NodeRenderOptions): void;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
private forEachRelevantBranch(callback);
private someRelevantBranch(predicateFunction);
}

View File

@ -0,0 +1,34 @@
import { ExpressionNode, Node, NodeBase } from './shared/Node';
import Variable from '../variables/Variable';
import ExecutionPathOptions from '../ExecutionPathOptions';
import CallOptions from '../CallOptions';
import MagicString from 'magic-string';
import { ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from './shared/Expression';
import { NodeType } from './NodeType';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import { ObjectPath, ObjectPathKey } from '../values';
export declare function isMemberExpression(node: Node): node is MemberExpression;
export default class MemberExpression extends NodeBase {
type: NodeType.MemberExpression;
object: ExpressionNode;
property: ExpressionNode;
computed: boolean;
propertyKey: ObjectPathKey;
variable: Variable;
private isBound;
private replacement;
private arePropertyReadSideEffectsChecked;
bind(): void;
private resolveNamespaceVariables(baseVariable, path);
forEachReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, callback: ForEachReturnExpressionCallback, options: ExecutionPathOptions): void;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
includeInBundle(): boolean;
initialiseNode(): void;
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
private disallowNamespaceReassignment();
render(code: MagicString, options: RenderOptions, {renderedParentType, isCalleeOfRenderedParent}?: NodeRenderOptions): void;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,16 @@
import { ExpressionNode, NodeBase } from './shared/Node';
import ExecutionPathOptions from '../ExecutionPathOptions';
import FunctionExpression from './FunctionExpression';
import CallOptions from '../CallOptions';
import { NodeType } from './NodeType';
import { ObjectPath } from '../values';
export default class MethodDefinition extends NodeBase {
type: NodeType.MethodDefinition;
key: ExpressionNode;
value: FunctionExpression;
kind: 'constructor' | 'method' | 'get' | 'set';
computed: boolean;
static: boolean;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,14 @@
import CallOptions from '../CallOptions';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { ExpressionNode, NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
import { ObjectPath } from '../values';
export default class NewExpression extends NodeBase {
type: NodeType.NewExpression;
callee: ExpressionNode;
arguments: ExpressionNode[];
_callOptions: CallOptions;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
initialiseNode(): void;
}

View File

@ -0,0 +1,64 @@
export declare const enum NodeType {
ArrayExpression = "ArrayExpression",
ArrayPattern = "ArrayPattern",
ArrowFunctionExpression = "ArrowFunctionExpression",
AssignmentExpression = "AssignmentExpression",
AssignmentPattern = "AssignmentPattern",
AwaitExpression = "AwaitExpression",
BinaryExpression = "BinaryExpression",
BlockStatement = "BlockStatement",
BreakStatement = "BreakStatement",
CallExpression = "CallExpression",
CatchClause = "CatchClause",
ClassBody = "ClassBody",
ClassDeclaration = "ClassDeclaration",
ClassExpression = "ClassExpression",
ConditionalExpression = "ConditionalExpression",
DoWhileStatement = "DoWhileStatement",
EmptyStatement = "EmptyStatement",
ExportAllDeclaration = "ExportAllDeclaration",
ExportDefaultDeclaration = "ExportDefaultDeclaration",
ExportNamedDeclaration = "ExportNamedDeclaration",
ExportSpecifier = "ExportSpecifier",
ExpressionStatement = "ExpressionStatement",
ForStatement = "ForStatement",
ForInStatement = "ForInStatement",
ForOfStatement = "ForOfStatement",
FunctionDeclaration = "FunctionDeclaration",
FunctionExpression = "FunctionExpression",
Identifier = "Identifier",
IfStatement = "IfStatement",
Import = "Import",
ImportDeclaration = "ImportDeclaration",
ImportDefaultSpecifier = "ImportDefaultSpecifier",
ImportNamespaceSpecifier = "ImportNamespaceSpecifier",
ImportSpecifier = "ImportSpecifier",
LabeledStatement = "LabeledStatement",
Literal = "Literal",
LogicalExpression = "LogicalExpression",
MemberExpression = "MemberExpression",
MethodDefinition = "MethodDefinition",
NewExpression = "NewExpression",
ObjectExpression = "ObjectExpression",
ObjectPattern = "ObjectPattern",
Program = "Program",
Property = "Property",
RestElement = "RestElement",
ReturnStatement = "ReturnStatement",
SequenceExpression = "SequenceExpression",
SpreadElement = "SpreadElement",
SwitchCase = "SwitchCase",
SwitchStatement = "SwitchStatement",
TaggedTemplateExpression = "TaggedTemplateExpression",
TemplateElement = "TemplateElement",
TemplateLiteral = "TemplateLiteral",
ThisExpression = "ThisExpression",
ThrowStatement = "ThrowStatement",
TryStatement = "TryStatement",
UnaryExpression = "UnaryExpression",
UpdateExpression = "UpdateExpression",
VariableDeclarator = "VariableDeclarator",
VariableDeclaration = "VariableDeclaration",
WhileStatement = "WhileStatement",
YieldExpression = "YieldExpression",
}

View File

@ -0,0 +1,25 @@
import Property from './Property';
import CallOptions from '../CallOptions';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from './shared/Expression';
import { ObjectPath, ObjectPathKey } from '../values';
import { Node, NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import MagicString from 'magic-string';
export declare function isObjectExpression(node: Node): node is ObjectExpression;
export default class ObjectExpression extends NodeBase {
type: NodeType.ObjectExpression;
properties: Property[];
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
forEachReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, callback: ForEachReturnExpressionCallback, options: ExecutionPathOptions): void;
_getPossiblePropertiesWithName(name: ObjectPathKey, kinds: ObjectPath): {
properties: Property[];
hasCertainHit: boolean;
};
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
render(code: MagicString, options: RenderOptions, {renderedParentType}?: NodeRenderOptions): void;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,15 @@
import AssignmentProperty from './AssignmentProperty';
import Scope from '../scopes/Scope';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { ExpressionEntity } from './shared/Expression';
import { PatternNode } from './shared/Pattern';
import { NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
import { ObjectPath } from '../values';
export default class ObjectPattern extends NodeBase implements PatternNode {
type: NodeType.ObjectPattern;
properties: AssignmentProperty[];
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
initialiseAndDeclare(parentScope: Scope, kind: string, init: ExpressionEntity | null): void;
}

View File

@ -0,0 +1,9 @@
import MagicString from 'magic-string';
import { NodeBase, StatementNode } from './shared/Node';
import { NodeType } from './NodeType';
import { RenderOptions } from '../../utils/renderHelpers';
export default class Program extends NodeBase {
type: NodeType.Program;
body: StatementNode[];
render(code: MagicString, options: RenderOptions): void;
}

View File

@ -0,0 +1,30 @@
import { ExpressionNode, Node, NodeBase } from './shared/Node';
import CallOptions from '../CallOptions';
import { ObjectPath } from '../values';
import ExecutionPathOptions from '../ExecutionPathOptions';
import Scope from '../scopes/Scope';
import MagicString from 'magic-string';
import { ExpressionEntity, ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from './shared/Expression';
import { NodeType } from './NodeType';
import { RenderOptions } from '../../utils/renderHelpers';
export declare function isProperty(node: Node): node is Property;
export default class Property extends NodeBase {
type: NodeType.Property;
key: ExpressionNode;
value: ExpressionNode;
kind: 'init' | 'get' | 'set';
method: boolean;
shorthand: boolean;
computed: boolean;
private _accessorCallOptions;
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
forEachReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, callback: ForEachReturnExpressionCallback, options: ExecutionPathOptions): void;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
initialiseAndDeclare(parentScope: Scope, kind: string, _init: ExpressionEntity | null): void;
initialiseNode(_parentScope: Scope): void;
render(code: MagicString, options: RenderOptions): void;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,14 @@
import { ObjectPath } from '../values';
import ExecutionPathOptions from '../ExecutionPathOptions';
import Scope from '../scopes/Scope';
import { PatternNode } from './shared/Pattern';
import { ExpressionEntity } from './shared/Expression';
import { NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
export default class RestElement extends NodeBase implements PatternNode {
type: NodeType.RestElement;
argument: PatternNode;
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
initialiseAndDeclare(parentScope: Scope, kind: string, _init: ExpressionEntity | null): void;
}

View File

@ -0,0 +1,9 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeType } from './NodeType';
import { ExpressionNode, StatementBase } from './shared/Node';
export default class ReturnStatement extends StatementBase {
type: NodeType.ReturnStatement;
argument: ExpressionNode | null;
hasEffects(options: ExecutionPathOptions): boolean;
initialiseNode(): void;
}

View File

@ -0,0 +1,21 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import MagicString from 'magic-string';
import { ExpressionNode, NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import { ObjectPath } from '../values';
import CallOptions from '../CallOptions';
import { ForEachReturnExpressionCallback } from './shared/Expression';
export default class SequenceExpression extends NodeBase {
type: NodeType.SequenceExpression;
expressions: ExpressionNode[];
forEachReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, callback: ForEachReturnExpressionCallback, options: ExecutionPathOptions): void;
getValue(): any;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
includeInBundle(): boolean;
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
render(code: MagicString, options: RenderOptions, {renderedParentType, isCalleeOfRenderedParent}?: NodeRenderOptions): void;
}

View File

@ -0,0 +1,6 @@
import { ExpressionNode } from './shared/Node';
import { NodeType } from './NodeType';
export default interface SpreadElement extends ExpressionNode {
type: NodeType.SpreadElement;
argument: ExpressionNode;
}

View File

@ -0,0 +1,11 @@
import { ExpressionNode, NodeBase, StatementNode } from './shared/Node';
import { NodeType } from './NodeType';
import { RenderOptions } from '../../utils/renderHelpers';
import MagicString from 'magic-string';
export default class SwitchCase extends NodeBase {
type: NodeType.SwitchCase;
test: ExpressionNode | null;
consequent: StatementNode[];
includeInBundle(): boolean;
render(code: MagicString, options: RenderOptions): void;
}

View File

@ -0,0 +1,12 @@
import SwitchCase from './SwitchCase';
import ExecutionPathOptions from '../ExecutionPathOptions';
import Scope from '../scopes/Scope';
import { NodeType } from './NodeType';
import { ExpressionNode, StatementBase } from './shared/Node';
export default class SwitchStatement extends StatementBase {
type: NodeType.SwitchStatement;
discriminant: ExpressionNode;
cases: SwitchCase[];
hasEffects(options: ExecutionPathOptions): boolean;
initialiseScope(parentScope: Scope): void;
}

View File

@ -0,0 +1,13 @@
import TemplateLiteral from './TemplateLiteral';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeType } from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
export default class TaggedTemplateExpression extends NodeBase {
type: NodeType.TaggedTemplateExpression;
tag: ExpressionNode;
quasi: TemplateLiteral;
private _callOptions;
bindNode(): void;
hasEffects(options: ExecutionPathOptions): boolean;
initialiseNode(): void;
}

View File

@ -0,0 +1,12 @@
import { NodeBase } from './shared/Node';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeType } from './NodeType';
export default class TemplateElement extends NodeBase {
type: NodeType.TemplateElement;
tail: boolean;
value: {
cooked: string;
raw: string;
};
hasEffects(_options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,12 @@
import TemplateElement from './TemplateElement';
import MagicString from 'magic-string';
import { ExpressionNode, Node, NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
import { RenderOptions } from '../../utils/renderHelpers';
export declare function isTemplateLiteral(node: Node): node is TemplateLiteral;
export default class TemplateLiteral extends NodeBase {
type: NodeType.TemplateLiteral;
quasis: TemplateElement[];
expressions: ExpressionNode[];
render(code: MagicString, options: RenderOptions): void;
}

View File

@ -0,0 +1,17 @@
import ThisVariable from '../variables/ThisVariable';
import ExecutionPathOptions from '../ExecutionPathOptions';
import MagicString from 'magic-string';
import { NodeBase } from './shared/Node';
import { NodeType } from './NodeType';
import { RenderOptions } from '../../utils/renderHelpers';
import { ObjectPath } from '../values';
export default class ThisExpression extends NodeBase {
type: NodeType.ThisExpression;
variable: ThisVariable;
alias: string;
initialiseNode(): void;
bindNode(): void;
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
render(code: MagicString, _options: RenderOptions): void;
}

View File

@ -0,0 +1,8 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeType } from './NodeType';
import { ExpressionNode, StatementBase } from './shared/Node';
export default class ThrowStatement extends StatementBase {
type: NodeType.ThrowStatement;
argument: ExpressionNode;
hasEffects(_options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,16 @@
import { ObjectPath } from '../values';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeType } from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
export default class UnaryExpression extends NodeBase {
type: NodeType.UnaryExpression;
operator: '-' | '+' | '!' | '~' | 'typeof' | 'void' | 'delete';
prefix: boolean;
argument: ExpressionNode;
value: any;
bindNode(): void;
getValue(): any;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
initialiseNode(): void;
}

View File

@ -0,0 +1,5 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeBase } from './shared/Node';
export default class UnknownNode extends NodeBase {
hasEffects(_options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,13 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeType } from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
import { ObjectPath } from '../values';
export default class UpdateExpression extends NodeBase {
type: NodeType.UpdateExpression;
operator: '++' | '--' | '**';
argument: ExpressionNode;
prefix: boolean;
bindNode(): void;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,21 @@
import { Node, NodeBase } from './shared/Node';
import ExecutionPathOptions from '../ExecutionPathOptions';
import VariableDeclarator from './VariableDeclarator';
import MagicString from 'magic-string';
import { NodeType } from './NodeType';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import { ObjectPath } from '../values';
export declare function isVariableDeclaration(node: Node): node is VariableDeclaration;
export default class VariableDeclaration extends NodeBase {
type: NodeType.VariableDeclaration;
declarations: VariableDeclarator[];
kind: 'var' | 'let' | 'const';
reassignPath(_path: ObjectPath, _options: ExecutionPathOptions): void;
hasEffectsWhenAssignedAtPath(_path: ObjectPath, _options: ExecutionPathOptions): boolean;
includeWithAllDeclaredVariables(): boolean;
includeInBundle(): boolean;
initialiseChildren(): void;
render(code: MagicString, options: RenderOptions, nodeRenderOptions?: NodeRenderOptions): void;
private renderReplacedDeclarations(code, options, {start, end, isNoStatement});
private renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, addSemicolon);
}

View File

@ -0,0 +1,13 @@
import { ExpressionNode, NodeBase } from './shared/Node';
import Scope from '../scopes/Scope';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { PatternNode } from './shared/Pattern';
import { NodeType } from './NodeType';
import { ObjectPath } from '../values';
export default class VariableDeclarator extends NodeBase {
type: NodeType.VariableDeclarator;
id: PatternNode;
init: ExpressionNode | null;
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
initialiseDeclarator(parentScope: Scope, kind: string): void;
}

View File

@ -0,0 +1,9 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeType } from './NodeType';
import { ExpressionNode, StatementBase, StatementNode } from './shared/Node';
export default class WhileStatement extends StatementBase {
type: NodeType.WhileStatement;
test: ExpressionNode;
body: StatementNode;
hasEffects(options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,9 @@
import ExecutionPathOptions from '../ExecutionPathOptions';
import { NodeType } from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
export default class YieldExpression extends NodeBase {
type: NodeType.YieldExpression;
argument: ExpressionNode | null;
delegate: boolean;
hasEffects(options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,6 @@
import { NodeBase } from './shared/Node';
declare const nodes: {
[name: string]: typeof NodeBase;
};
export { NodeType } from './NodeType';
export default nodes;

View File

@ -0,0 +1,17 @@
import Scope from '../../scopes/Scope';
import CallOptions from '../../CallOptions';
import ExecutionPathOptions from '../../ExecutionPathOptions';
import Identifier from '../Identifier';
import ClassBody from '../ClassBody';
import { ExpressionNode, NodeBase } from './Node';
import { ObjectPath } from '../../values';
export default class ClassNode extends NodeBase {
body: ClassBody;
superClass: ExpressionNode | null;
id: Identifier | null;
hasEffectsWhenAccessedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
initialiseChildren(_parentScope: Scope): void;
initialiseScope(parentScope: Scope): void;
}

View File

@ -0,0 +1,21 @@
import { WritableEntity } from '../../Entity';
import CallOptions from '../../CallOptions';
import ExecutionPathOptions from '../../ExecutionPathOptions';
import { ObjectPath } from '../../values';
export declare type PredicateFunction = (node: ExpressionEntity) => boolean;
export declare type SomeReturnExpressionCallback = (options: ExecutionPathOptions) => PredicateFunction;
export declare type ForEachReturnExpressionCallback = (options: ExecutionPathOptions) => (node: ExpressionEntity) => void;
export interface ExpressionEntity extends WritableEntity {
/**
* Executes the callback on each possible return expression when calling this node.
*/
forEachReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, callback: ForEachReturnExpressionCallback, options: ExecutionPathOptions): void;
getValue(): any;
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
/**
* Should return true if some possible return expression when called at the given
* path returns true.
*/
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,25 @@
import FunctionScope from '../../scopes/FunctionScope';
import BlockScope from '../../scopes/FunctionScope';
import BlockStatement from '../BlockStatement';
import Identifier from '../Identifier';
import CallOptions from '../../CallOptions';
import ExecutionPathOptions from '../../ExecutionPathOptions';
import { PatternNode } from './Pattern';
import { ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from './Expression';
import { NodeBase } from './Node';
import { ObjectPath } from '../../values';
export default class FunctionNode extends NodeBase {
id: Identifier;
body: BlockStatement;
scope: BlockScope;
params: PatternNode[];
bindNode(): void;
forEachReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, callback: ForEachReturnExpressionCallback, options: ExecutionPathOptions): void;
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
includeInBundle(): boolean;
initialiseScope(parentScope: FunctionScope): void;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,133 @@
import ExecutionPathOptions from '../../ExecutionPathOptions';
import Scope from '../../scopes/Scope';
import Module from '../../../Module';
import MagicString from 'magic-string';
import Variable from '../../variables/Variable';
import { ExpressionEntity, ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from './Expression';
import CallOptions from '../../CallOptions';
import { ObjectPath } from '../../values';
import { Entity } from '../../Entity';
import { NodeRenderOptions, RenderOptions } from '../../../utils/renderHelpers';
export interface Node extends Entity {
end: number;
included: boolean;
keys: string[];
module: Module;
needsBoundaries?: boolean;
parent: Node | {
type?: string;
};
start: number;
type: string;
variable?: Variable;
__enhanced: boolean;
/**
* Called once all nodes have been initialised and the scopes have been populated.
* Usually one should not override this function but override bindNode and/or
* bindChildren instead.
*/
bind(): void;
eachChild(callback: (node: Node) => void): void;
/**
* Determine if this Node would have an effect on the bundle.
* This is usually true for already included nodes. Exceptions are e.g. break statements
* which only have an effect if their surrounding loop or switch statement is included.
* The options pass on information like this about the current execution path.
*/
hasEffects(options: ExecutionPathOptions): boolean;
/**
* Includes the node in the bundle. Children are usually included if they are
* necessary for this node (e.g. a function body) or if they have effects.
* Necessary variables need to be included as well. Should return true if any
* nodes or variables have been added that were missing before.
*/
includeInBundle(): boolean;
/**
* Alternative version of includeInBundle to override the default behaviour of
* declarations to only include nodes for declarators that have an effect. Necessary
* for for-loops that do not use a declared loop variable.
*/
includeWithAllDeclaredVariables(): boolean;
/**
* Assign a scope to this node and make sure all children have the right scopes.
* Perform any additional initialisation that does not depend on the scope being
* populated with variables.
* Usually one should not override this function but override initialiseScope,
* initialiseNode and/or initialiseChildren instead. BlockScopes have a special
* alternative initialisation initialiseAndReplaceScope.
*/
initialise(parentScope: Scope): void;
initialiseAndDeclare(parentScope: Scope, kind: string, init: ExpressionEntity | null): void;
render(code: MagicString, options: RenderOptions, nodeRenderOptions?: NodeRenderOptions): void;
/**
* Start a new execution path to determine if this node has an effect on the bundle and
* should therefore be included. Included nodes should always be included again in subsequent
* visits as the inclusion of additional variables may require the inclusion of more child
* nodes in e.g. block statements.
*/
shouldBeIncluded(): boolean;
someChild(callback: (node: Node) => boolean): boolean;
}
export interface StatementNode extends Node {
}
export interface ExpressionNode extends ExpressionEntity, Node {
}
export declare class NodeBase implements ExpressionNode {
type: string;
keys: string[];
included: boolean;
scope: Scope;
start: number;
end: number;
module: Module;
parent: Node | {
type?: string;
};
__enhanced: boolean;
constructor();
bind(): void;
/**
* Override to control on which children "bind" is called.
*/
bindChildren(): void;
/**
* Override this to bind assignments to variables and do any initialisations that
* require the scopes to be populated with variables.
*/
bindNode(): void;
eachChild(callback: (node: Node) => void): void;
forEachReturnExpressionWhenCalledAtPath(_path: ObjectPath, _callOptions: CallOptions, _callback: ForEachReturnExpressionCallback, _options: ExecutionPathOptions): void;
getValue(): {
toString: () => string;
};
hasEffects(options: ExecutionPathOptions): boolean;
hasEffectsWhenAccessedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(_path: ObjectPath, _options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(_path: ObjectPath, _callOptions: CallOptions, _options: ExecutionPathOptions): boolean;
private hasIncludedChild();
includeInBundle(): boolean;
includeWithAllDeclaredVariables(): boolean;
initialise(parentScope: Scope): void;
initialiseAndDeclare(_parentScope: Scope, _kind: string, _init: ExpressionEntity | null): void;
/**
* Override to change how and with what scopes children are initialised
*/
initialiseChildren(_parentScope: Scope): void;
/**
* Override to perform special initialisation steps after the scope is initialised
*/
initialiseNode(_parentScope: Scope): void;
/**
* Override if this scope should receive a different scope than the parent scope.
*/
initialiseScope(parentScope: Scope): void;
insertSemicolon(code: MagicString): void;
locate(): any;
reassignPath(_path: ObjectPath, _options: ExecutionPathOptions): void;
render(code: MagicString, options: RenderOptions): void;
shouldBeIncluded(): boolean;
someChild(callback: (node: NodeBase) => boolean): boolean;
someReturnExpressionWhenCalledAtPath(_path: ObjectPath, _callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
toString(): string;
}
export { NodeBase as StatementBase };

View File

@ -0,0 +1,4 @@
import { WritableEntity } from '../../Entity';
import { Node } from './Node';
export interface PatternNode extends WritableEntity, Node {
}

View File

@ -0,0 +1,4 @@
declare const pureFunctions: {
[name: string]: boolean;
};
export default pureFunctions;