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,15 @@
import LocalVariable from './LocalVariable';
import { ObjectPath } from '../values';
import ExecutionPathOptions from '../ExecutionPathOptions';
import CallOptions from '../CallOptions';
import ParameterVariable from './ParameterVariable';
import { SomeReturnExpressionCallback } from '../nodes/shared/Expression';
export default class ArgumentsVariable extends LocalVariable {
private _parameters;
constructor(parameters: ParameterVariable[]);
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,16 @@
import LocalVariable from './LocalVariable';
import ExportDefaultDeclaration from '../nodes/ExportDefaultDeclaration';
import Identifier from '../nodes/Identifier';
import Variable from './Variable';
export declare function isExportDefaultVariable(variable: Variable): variable is ExportDefaultVariable;
export default class ExportDefaultVariable extends LocalVariable {
isDefault: true;
hasId: boolean;
private _original;
constructor(name: string, exportDefaultDeclaration: ExportDefaultDeclaration);
addReference(identifier: Identifier): void;
getName(reset?: boolean): string;
referencesOriginal(): boolean;
getOriginalVariableName(): string;
setOriginalVariable(original: Variable): void;
}

View File

@ -0,0 +1,12 @@
import Variable from './Variable';
import Identifier from '../nodes/Identifier';
import ExternalModule from '../../ExternalModule';
export declare function isExternalVariable(variable: Variable): variable is ExternalVariable;
export default class ExternalVariable extends Variable {
module: ExternalModule;
isExternal: true;
isNamespace: boolean;
constructor(module: ExternalModule, name: string);
addReference(identifier: Identifier): void;
includeVariable(): boolean;
}

View File

@ -0,0 +1,10 @@
import Variable from './Variable';
import { ObjectPath } from '../values';
export default class GlobalVariable extends Variable {
isExternal: true;
isGlobal: true;
constructor(name: string);
hasEffectsWhenAccessedAtPath(path: ObjectPath): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath): boolean;
private isPureFunctionMember(path);
}

View File

@ -0,0 +1,21 @@
import Variable from './Variable';
import VariableReassignmentTracker from './VariableReassignmentTracker';
import ExecutionPathOptions from '../ExecutionPathOptions';
import CallOptions from '../CallOptions';
import Identifier from '../nodes/Identifier';
import ExportDefaultDeclaration from '../nodes/ExportDefaultDeclaration';
import { ExpressionEntity, ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from '../nodes/shared/Expression';
import { ObjectPath } from '../values';
export default class LocalVariable extends Variable {
declarations: Set<Identifier | ExportDefaultDeclaration>;
boundExpressions: VariableReassignmentTracker;
constructor(name: string, declarator: Identifier | ExportDefaultDeclaration | null, init: ExpressionEntity);
addDeclaration(identifier: Identifier): 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;
includeVariable(): boolean;
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
}

View File

@ -0,0 +1,20 @@
import Variable from './Variable';
import Identifier from '../nodes/Identifier';
import Module from '../../Module';
import { RenderOptions } from '../../utils/renderHelpers';
export declare function isNamespaceVariable(variable: Variable): variable is NamespaceVariable;
export default class NamespaceVariable extends Variable {
isNamespace: true;
module: Module;
needsNamespaceBlock: boolean;
referencedEarly: boolean;
originals: {
[name: string]: Variable;
};
references: Identifier[];
constructor(module: Module);
addReference(identifier: Identifier): void;
includeVariable(): boolean;
renderFirst(): boolean;
renderBlock(options: RenderOptions): string;
}

View File

@ -0,0 +1,5 @@
import ReplaceableInitializationVariable from './ReplaceableInitializationVariable';
import Identifier from '../nodes/Identifier';
export default class ParameterVariable extends ReplaceableInitializationVariable {
constructor(identifier: Identifier);
}

View File

@ -0,0 +1,14 @@
import LocalVariable from './LocalVariable';
import { ObjectPath } from '../values';
import ExecutionPathOptions from '../ExecutionPathOptions';
import CallOptions from '../CallOptions';
import Identifier from '../nodes/Identifier';
import { ExpressionEntity, SomeReturnExpressionCallback } from '../nodes/shared/Expression';
export default class ReplaceableInitializationVariable extends LocalVariable {
constructor(name: string, declarator: Identifier | null);
hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, options: ExecutionPathOptions): boolean;
someReturnExpressionWhenCalledAtPath(path: ObjectPath, callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
_getInit(options: ExecutionPathOptions): ExpressionEntity;
}

View File

@ -0,0 +1,4 @@
import ReplaceableInitializationVariable from './ReplaceableInitializationVariable';
export default class ThisVariable extends ReplaceableInitializationVariable {
constructor();
}

View File

@ -0,0 +1,43 @@
import { ObjectPath } from '../values';
import CallOptions from '../CallOptions';
import ExecutionPathOptions from '../ExecutionPathOptions';
import Identifier from '../nodes/Identifier';
import { ExpressionEntity, ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from '../nodes/shared/Expression';
export default class Variable implements ExpressionEntity {
exportName?: string;
included: boolean;
isExternal?: boolean;
isGlobal?: boolean;
isDefault?: boolean;
isNamespace?: boolean;
isReassigned: boolean;
isId: boolean;
name: string;
reexported?: boolean;
safeName: string;
constructor(name: string);
/**
* Binds identifiers that reference this variable to this variable.
* Necessary to be able to change variable names.
*/
addReference(_identifier: Identifier): void;
reassignPath(_path: ObjectPath, _options: ExecutionPathOptions): void;
forEachReturnExpressionWhenCalledAtPath(_path: ObjectPath, _callOptions: CallOptions, _callback: ForEachReturnExpressionCallback, _options: ExecutionPathOptions): void;
getName(reset?: boolean): string;
getValue(): {
toString: () => string;
};
hasEffectsWhenAccessedAtPath(path: ObjectPath, _options: ExecutionPathOptions): boolean;
hasEffectsWhenAssignedAtPath(_path: ObjectPath, _options: ExecutionPathOptions): boolean;
hasEffectsWhenCalledAtPath(_path: ObjectPath, _callOptions: CallOptions, _options: ExecutionPathOptions): boolean;
/**
* Marks this variable as being part of the bundle, which is usually the case when one of
* its identifiers becomes part of the bundle. Returns true if it has not been included
* previously.
* Once a variable is included, it should take care all its declarations are included.
*/
includeVariable(): boolean;
someReturnExpressionWhenCalledAtPath(_path: ObjectPath, _callOptions: CallOptions, predicateFunction: SomeReturnExpressionCallback, options: ExecutionPathOptions): boolean;
toString(): string;
setSafeName(name: string): void;
}

View File

@ -0,0 +1,11 @@
import { ObjectPath, PathCallback, PathPredicate } from '../values';
import ExecutionPathOptions from '../ExecutionPathOptions';
import { ExpressionEntity } from '../nodes/shared/Expression';
export default class VariableReassignmentTracker {
private _initialExpression;
private _reassignedPathTracker;
constructor(initialExpression: ExpressionEntity);
reassignPath(path: ObjectPath, options: ExecutionPathOptions): void;
forEachAtPath(path: ObjectPath, callback: PathCallback): void;
someAtPath(path: ObjectPath, predicateFunction: PathPredicate): boolean;
}