mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Move System module transform to end.
This commit is contained in:
@@ -2485,7 +2485,7 @@ namespace ts {
|
||||
&& (leftKind === SyntaxKind.ObjectLiteralExpression
|
||||
|| leftKind === SyntaxKind.ArrayLiteralExpression)) {
|
||||
// Destructuring assignments are ES6 syntax.
|
||||
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.DestructuringAssignment;
|
||||
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertDestructuringAssignment;
|
||||
}
|
||||
else if (operatorTokenKind === SyntaxKind.AsteriskAsteriskToken
|
||||
|| operatorTokenKind === SyntaxKind.AsteriskAsteriskEqualsToken) {
|
||||
|
||||
+48
-19
@@ -424,11 +424,16 @@ namespace ts {
|
||||
|
||||
export function some<T>(array: T[], predicate?: (value: T) => boolean): boolean {
|
||||
if (array) {
|
||||
for (const v of array) {
|
||||
if (!predicate || predicate(v)) {
|
||||
return true;
|
||||
if (predicate) {
|
||||
for (const v of array) {
|
||||
if (predicate(v)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return array.length > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -485,6 +490,14 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a value to an array, returning the array.
|
||||
*
|
||||
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
|
||||
* is created if `value` was appended.
|
||||
* @param value The value to append to the array. If `value` is `undefined`, nothing is
|
||||
* appended.
|
||||
*/
|
||||
export function append<T>(to: T[] | undefined, value: T | undefined): T[] | undefined {
|
||||
if (value === undefined) return to;
|
||||
if (to === undefined) to = [];
|
||||
@@ -492,14 +505,20 @@ namespace ts {
|
||||
return to;
|
||||
}
|
||||
|
||||
export function addRange<T>(to: T[], from: T[]): void {
|
||||
if (to && from) {
|
||||
for (const v of from) {
|
||||
if (v !== undefined) {
|
||||
to.push(v);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Appends a range of value to an array, returning the array.
|
||||
*
|
||||
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
|
||||
* is created if `value` was appended.
|
||||
* @param from The values to append to the array. If `from` is `undefined`, nothing is
|
||||
* appended. If an element of `from` is `undefined`, that element is not appended.
|
||||
*/
|
||||
export function addRange<T>(to: T[] | undefined, from: T[] | undefined): T[] | undefined {
|
||||
if (from === undefined) return to;
|
||||
for (const v of from) {
|
||||
to = append(to, v);
|
||||
}
|
||||
return to;
|
||||
}
|
||||
|
||||
export function rangeEquals<T>(array1: T[], array2: T[], pos: number, end: number) {
|
||||
@@ -512,33 +531,43 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element of an array if non-empty, `undefined` otherwise.
|
||||
*/
|
||||
export function firstOrUndefined<T>(array: T[]): T {
|
||||
return array && array.length > 0
|
||||
? array[0]
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last element of an array if non-empty, `undefined` otherwise.
|
||||
*/
|
||||
export function lastOrUndefined<T>(array: T[]): T {
|
||||
return array && array.length > 0
|
||||
? array[array.length - 1]
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the only element of an array if it contains only one element, `undefined` otherwise.
|
||||
*/
|
||||
export function singleOrUndefined<T>(array: T[]): T {
|
||||
return array && array.length === 1
|
||||
? array[0]
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the only element of an array if it contains only one element; otheriwse, returns the
|
||||
* array.
|
||||
*/
|
||||
export function singleOrMany<T>(array: T[]): T | T[] {
|
||||
return array && array.length === 1
|
||||
? array[0]
|
||||
: array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last element of an array if non-empty, undefined otherwise.
|
||||
*/
|
||||
export function lastOrUndefined<T>(array: T[]): T {
|
||||
return array && array.length > 0
|
||||
? array[array.length - 1]
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a binary search, finding the index at which 'value' occurs in 'array'.
|
||||
* If no such index is found, returns the 2's-complement of first index at which
|
||||
|
||||
+13
-27
@@ -1472,6 +1472,17 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a synthetic element to act as a placeholder for the beginning of a merged declaration in
|
||||
* order to properly emit exports.
|
||||
*/
|
||||
export function createMergeDeclarationMarker(original: Node) {
|
||||
const node = <MergeDeclarationMarker>createNode(SyntaxKind.MergeDeclarationMarker);
|
||||
node.emitNode = {};
|
||||
node.original = original;
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a synthetic expression to act as a placeholder for a not-emitted expression in
|
||||
* order to preserve comments or sourcemap positions.
|
||||
@@ -2206,7 +2217,7 @@ namespace ts {
|
||||
* Gets whether an identifier should only be referred to by its local name.
|
||||
*/
|
||||
export function isLocalName(node: Identifier) {
|
||||
return (getEmitFlags(node) & EmitFlags.ExportBindingName) === EmitFlags.LocalName;
|
||||
return (getEmitFlags(node) & EmitFlags.LocalName) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2228,32 +2239,7 @@ namespace ts {
|
||||
* name points to an exported symbol.
|
||||
*/
|
||||
export function isExportName(node: Identifier) {
|
||||
return (getEmitFlags(node) & EmitFlags.ExportBindingName) === EmitFlags.ExportName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the export binding name of a declaration for use in the left-hand side of assignment
|
||||
* expressions. This is primarily used for declarations that can be referred to by name in the
|
||||
* declaration's immediate scope (classes, enums, namespaces). If the declaration is exported
|
||||
* and the name is the target of an assignment expression, its export binding name should be
|
||||
* substituted with an expression that assigns *both* the local *and* export names of the
|
||||
* declaration. If an export binding name appears in any other position it should be treated
|
||||
* as a local name.
|
||||
*
|
||||
* @param node The declaration.
|
||||
* @param allowComments A value indicating whether comments may be emitted for the name.
|
||||
* @param allowSourceMaps A value indicating whether source maps may be emitted for the name.
|
||||
*/
|
||||
export function getExportBindingName(node: Declaration, allowComments?: boolean, allowSourceMaps?: boolean): Identifier {
|
||||
return getName(node, allowComments, allowSourceMaps, EmitFlags.ExportBindingName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether an identifier should be treated as both an export name and a local name when
|
||||
* it is the target of an assignment expression.
|
||||
*/
|
||||
export function isExportBindingName(node: Identifier) {
|
||||
return (getEmitFlags(node) & EmitFlags.ExportBindingName) === EmitFlags.ExportBindingName;
|
||||
return (getEmitFlags(node) & EmitFlags.ExportName) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -112,10 +112,6 @@ namespace ts {
|
||||
|
||||
transformers.push(transformTypeScript);
|
||||
|
||||
if (moduleKind === ModuleKind.System) {
|
||||
transformers.push(moduleTransformerMap[moduleKind] || moduleTransformerMap[ModuleKind.None]);
|
||||
}
|
||||
|
||||
if (jsx === JsxEmit.React) {
|
||||
transformers.push(transformJsx);
|
||||
}
|
||||
@@ -133,10 +129,10 @@ namespace ts {
|
||||
transformers.push(transformGenerators);
|
||||
}
|
||||
|
||||
if (moduleKind !== ModuleKind.System) {
|
||||
transformers.push(moduleTransformerMap[moduleKind] || moduleTransformerMap[ModuleKind.None]);
|
||||
}
|
||||
transformers.push(moduleTransformerMap[moduleKind] || moduleTransformerMap[ModuleKind.None]);
|
||||
|
||||
// The ES5 transformer is last so that it can substitute expressions like `exports.default`
|
||||
// for ES3.
|
||||
if (languageVersion < ScriptTarget.ES5) {
|
||||
transformers.push(transformES5);
|
||||
}
|
||||
|
||||
@@ -176,14 +176,15 @@ namespace ts {
|
||||
*
|
||||
* @param node The VariableDeclaration to flatten.
|
||||
* @param recordTempVariable A callback used to record new temporary variables.
|
||||
* @param nameSubstitution An optional callback used to substitute binding names.
|
||||
* @param createAssignmentCallback An optional callback used to create assignment expressions
|
||||
* for non-temporary variables.
|
||||
* @param visitor An optional visitor to use to visit expressions.
|
||||
*/
|
||||
export function flattenVariableDestructuringToExpression(
|
||||
context: TransformationContext,
|
||||
node: VariableDeclaration,
|
||||
recordTempVariable: (name: Identifier) => void,
|
||||
nameSubstitution?: (name: Identifier) => Expression,
|
||||
createAssignmentCallback?: (name: Identifier, value: Expression, location?: TextRange) => Expression,
|
||||
visitor?: (node: Node) => VisitResult<Node>) {
|
||||
|
||||
const pendingAssignments: Expression[] = [];
|
||||
@@ -195,18 +196,20 @@ namespace ts {
|
||||
return expression;
|
||||
|
||||
function emitAssignment(name: Identifier, value: Expression, location: TextRange, original: Node) {
|
||||
const left = nameSubstitution && nameSubstitution(name) || name;
|
||||
emitPendingAssignment(left, value, location, original);
|
||||
const expression = createAssignmentCallback
|
||||
? createAssignmentCallback(name, value, location)
|
||||
: createAssignment(name, value, location);
|
||||
|
||||
emitPendingAssignment(expression, original);
|
||||
}
|
||||
|
||||
function emitTempVariableAssignment(value: Expression, location: TextRange) {
|
||||
const name = createTempVariable(recordTempVariable);
|
||||
emitPendingAssignment(name, value, location, /*original*/ undefined);
|
||||
emitPendingAssignment(createAssignment(name, value, location), /*original*/ undefined);
|
||||
return name;
|
||||
}
|
||||
|
||||
function emitPendingAssignment(name: Expression, value: Expression, location: TextRange, original: Node) {
|
||||
const expression = createAssignment(name, value, location);
|
||||
function emitPendingAssignment(expression: Expression, original: Node) {
|
||||
expression.original = original;
|
||||
|
||||
// NOTE: this completely disables source maps, but aligns with the behavior of
|
||||
@@ -214,7 +217,6 @@ namespace ts {
|
||||
setEmitFlags(expression, EmitFlags.NoNestedSourceMaps);
|
||||
|
||||
pendingAssignments.push(expression);
|
||||
return expression;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -585,7 +585,7 @@ namespace ts {
|
||||
// }());
|
||||
|
||||
const variable = createVariableDeclaration(
|
||||
getDeclarationName(node, /*allowComments*/ true),
|
||||
getLocalName(node, /*allowComments*/ true),
|
||||
/*type*/ undefined,
|
||||
transformClassLikeDeclarationToExpression(node)
|
||||
);
|
||||
@@ -601,14 +601,12 @@ namespace ts {
|
||||
|
||||
// Add an `export default` statement for default exports (for `--target es5 --module es6`)
|
||||
if (hasModifier(node, ModifierFlags.Export)) {
|
||||
if (hasModifier(node, ModifierFlags.Default)) {
|
||||
const exportStatement = createExportDefault(getLocalName(node));
|
||||
setOriginalNode(exportStatement, statement);
|
||||
statements.push(exportStatement);
|
||||
}
|
||||
else {
|
||||
statements.push(createExternalModuleExport(getLocalName(node)));
|
||||
}
|
||||
const exportStatement = hasModifier(node, ModifierFlags.Default)
|
||||
? createExportDefault(getLocalName(node))
|
||||
: createExternalModuleExport(getLocalName(node));
|
||||
|
||||
setOriginalNode(exportStatement, statement);
|
||||
statements.push(exportStatement);
|
||||
}
|
||||
|
||||
const emitFlags = getEmitFlags(node);
|
||||
@@ -758,7 +756,7 @@ namespace ts {
|
||||
if (extendsClauseElement) {
|
||||
statements.push(
|
||||
createStatement(
|
||||
createExtendsHelper(currentSourceFile.externalHelpersModuleName, getDeclarationName(node)),
|
||||
createExtendsHelper(currentSourceFile.externalHelpersModuleName, getLocalName(node)),
|
||||
/*location*/ extendsClauseElement
|
||||
)
|
||||
);
|
||||
@@ -1694,7 +1692,7 @@ namespace ts {
|
||||
if (decl.initializer) {
|
||||
let assignment: Expression;
|
||||
if (isBindingPattern(decl.name)) {
|
||||
assignment = flattenVariableDestructuringToExpression(context, decl, hoistVariableDeclaration, /*nameSubstitution*/ undefined, visitor);
|
||||
assignment = flattenVariableDestructuringToExpression(context, decl, hoistVariableDeclaration, /*createAssignmentCallback*/ undefined, visitor);
|
||||
}
|
||||
else {
|
||||
assignment = createBinary(<Identifier>decl.name, SyntaxKind.EqualsToken, visitNode(decl.initializer, visitor, isExpression));
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -2353,7 +2353,7 @@ namespace ts {
|
||||
context,
|
||||
node,
|
||||
hoistVariableDeclaration,
|
||||
getNamespaceMemberNameWithSourceMapsAndWithoutComments,
|
||||
createNamespaceExportExpression,
|
||||
visitor
|
||||
);
|
||||
}
|
||||
@@ -2709,9 +2709,13 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
const notEmittedStatement = createNotEmittedStatement(statement);
|
||||
setEmitFlags(notEmittedStatement, EmitFlags.NoComments);
|
||||
statements.push(notEmittedStatement);
|
||||
// For an EnumDeclaration or ModuleDeclaration that merges with a preceeding
|
||||
// declaration we do not emit a leading variable declaration. To preserve the
|
||||
// begin/end semantics of the declararation and to properly handle exports
|
||||
// we wrap the leading variable declaration in a `MergeDeclarationMarker`.
|
||||
const mergeMarker = createMergeDeclarationMarker(statement);
|
||||
setEmitFlags(mergeMarker, EmitFlags.NoComments | EmitFlags.HasEndOfDeclarationMarker);
|
||||
statements.push(mergeMarker);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -3061,10 +3065,13 @@ namespace ts {
|
||||
createVariableStatement(
|
||||
visitNodes(node.modifiers, modifierVisitor, isModifier),
|
||||
createVariableDeclarationList([
|
||||
createVariableDeclaration(
|
||||
node.name,
|
||||
/*type*/ undefined,
|
||||
moduleReference
|
||||
setOriginalNode(
|
||||
createVariableDeclaration(
|
||||
node.name,
|
||||
/*type*/ undefined,
|
||||
moduleReference
|
||||
),
|
||||
node
|
||||
)
|
||||
]),
|
||||
node
|
||||
@@ -3152,6 +3159,10 @@ namespace ts {
|
||||
);
|
||||
}
|
||||
|
||||
function createNamespaceExportExpression(exportName: Identifier, exportValue: Expression, location?: TextRange) {
|
||||
return createAssignment(getNamespaceMemberNameWithSourceMapsAndWithoutComments(exportName), exportValue, location);
|
||||
}
|
||||
|
||||
function getNamespaceMemberNameWithSourceMapsAndWithoutComments(name: Identifier) {
|
||||
return getNamespaceMemberName(currentNamespaceContainerName, name, /*allowComments*/ false, /*allowSourceMaps*/ true);
|
||||
}
|
||||
@@ -3343,11 +3354,11 @@ namespace ts {
|
||||
|
||||
function trySubstituteNamespaceExportedName(node: Identifier): Expression {
|
||||
// If this is explicitly a local name, do not substitute.
|
||||
if (enabledSubstitutions & applicableSubstitutions && (getEmitFlags(node) & EmitFlags.LocalName) === 0) {
|
||||
if (enabledSubstitutions & applicableSubstitutions && !isLocalName(node)) {
|
||||
// If we are nested within a namespace declaration, we may need to qualifiy
|
||||
// an identifier that is exported from a merged namespace.
|
||||
const container = resolver.getReferencedExportContainer(node, /*prefixLocals*/ false);
|
||||
if (container) {
|
||||
if (container && container.kind !== SyntaxKind.SourceFile) {
|
||||
const substitute =
|
||||
(applicableSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && container.kind === SyntaxKind.ModuleDeclaration) ||
|
||||
(applicableSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && container.kind === SyntaxKind.EnumDeclaration);
|
||||
|
||||
+39
-14
@@ -362,6 +362,7 @@ namespace ts {
|
||||
// Transformation nodes
|
||||
NotEmittedStatement,
|
||||
PartiallyEmittedExpression,
|
||||
MergeDeclarationMarker,
|
||||
EndOfDeclarationMarker,
|
||||
|
||||
// Enum value count
|
||||
@@ -1156,6 +1157,21 @@ namespace ts {
|
||||
right: Expression;
|
||||
}
|
||||
|
||||
export interface AssignmentExpression extends BinaryExpression {
|
||||
left: LeftHandSideExpression;
|
||||
operatorToken: Token<SyntaxKind.EqualsToken>;
|
||||
}
|
||||
|
||||
export interface ObjectDestructuringAssignment extends AssignmentExpression {
|
||||
left: ObjectLiteralExpression;
|
||||
}
|
||||
|
||||
export interface ArrayDestructuringAssignment extends AssignmentExpression {
|
||||
left: ArrayLiteralExpression;
|
||||
}
|
||||
|
||||
export type DestructuringAssignment = ObjectDestructuringAssignment | ArrayDestructuringAssignment;
|
||||
|
||||
export interface ConditionalExpression extends Expression {
|
||||
kind: SyntaxKind.ConditionalExpression;
|
||||
condition: Expression;
|
||||
@@ -1436,6 +1452,14 @@ namespace ts {
|
||||
kind: SyntaxKind.EndOfDeclarationMarker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the beginning of a merged transformed declaration.
|
||||
*/
|
||||
/* @internal */
|
||||
export interface MergeDeclarationMarker extends Statement {
|
||||
kind: SyntaxKind.MergeDeclarationMarker;
|
||||
}
|
||||
|
||||
export interface EmptyStatement extends Statement {
|
||||
kind: SyntaxKind.EmptyStatement;
|
||||
}
|
||||
@@ -3380,22 +3404,23 @@ namespace ts {
|
||||
Generator = 1 << 10,
|
||||
ContainsGenerator = 1 << 11,
|
||||
DestructuringAssignment = 1 << 12,
|
||||
ContainsDestructuringAssignment = 1 << 13,
|
||||
|
||||
// Markers
|
||||
// - Flags used to indicate that a subtree contains a specific transformation.
|
||||
ContainsDecorators = 1 << 13,
|
||||
ContainsPropertyInitializer = 1 << 14,
|
||||
ContainsLexicalThis = 1 << 15,
|
||||
ContainsCapturedLexicalThis = 1 << 16,
|
||||
ContainsLexicalThisInComputedPropertyName = 1 << 17,
|
||||
ContainsDefaultValueAssignments = 1 << 18,
|
||||
ContainsParameterPropertyAssignments = 1 << 19,
|
||||
ContainsSpreadElementExpression = 1 << 20,
|
||||
ContainsComputedPropertyName = 1 << 21,
|
||||
ContainsBlockScopedBinding = 1 << 22,
|
||||
ContainsBindingPattern = 1 << 23,
|
||||
ContainsYield = 1 << 24,
|
||||
ContainsHoistedDeclarationOrCompletion = 1 << 25,
|
||||
ContainsDecorators = 1 << 14,
|
||||
ContainsPropertyInitializer = 1 << 15,
|
||||
ContainsLexicalThis = 1 << 16,
|
||||
ContainsCapturedLexicalThis = 1 << 17,
|
||||
ContainsLexicalThisInComputedPropertyName = 1 << 18,
|
||||
ContainsDefaultValueAssignments = 1 << 19,
|
||||
ContainsParameterPropertyAssignments = 1 << 20,
|
||||
ContainsSpreadElementExpression = 1 << 21,
|
||||
ContainsComputedPropertyName = 1 << 22,
|
||||
ContainsBlockScopedBinding = 1 << 23,
|
||||
ContainsBindingPattern = 1 << 24,
|
||||
ContainsYield = 1 << 25,
|
||||
ContainsHoistedDeclarationOrCompletion = 1 << 26,
|
||||
|
||||
HasComputedFlags = 1 << 29, // Transform flags have been computed.
|
||||
|
||||
@@ -3407,6 +3432,7 @@ namespace ts {
|
||||
AssertES2016 = ES2016 | ContainsES2016,
|
||||
AssertES2015 = ES2015 | ContainsES2015,
|
||||
AssertGenerator = Generator | ContainsGenerator,
|
||||
AssertDestructuringAssignment = DestructuringAssignment | ContainsDestructuringAssignment,
|
||||
|
||||
// Scope Exclusions
|
||||
// - Bitmasks that exclude flags from propagating out of a specific context
|
||||
@@ -3464,7 +3490,6 @@ namespace ts {
|
||||
NoNestedComments = 1 << 16,
|
||||
ExportName = 1 << 17, // Ensure an export prefix is added for an identifier that points to an exported declaration with a local name (see SymbolFlags.ExportHasLocal).
|
||||
LocalName = 1 << 18, // Ensure an export prefix is not added for an identifier that points to an exported declaration.
|
||||
ExportBindingName = LocalName | ExportName,
|
||||
Indented = 1 << 19, // Adds an explicit extra indentation level for class and function bodies when printing (used to match old emitter).
|
||||
NoIndentation = 1 << 20, // Do not indent the node.
|
||||
AsyncFunctionBody = 1 << 21,
|
||||
|
||||
+28
-22
@@ -3084,7 +3084,13 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function isDestructuringAssignment(node: Node): node is BinaryExpression {
|
||||
export function isAssignmentExpression(node: Node): node is AssignmentExpression {
|
||||
return isBinaryExpression(node)
|
||||
&& isAssignmentOperator(node.operatorToken.kind)
|
||||
&& isLeftHandSideExpression(node.left);
|
||||
}
|
||||
|
||||
export function isDestructuringAssignment(node: Node): node is DestructuringAssignment {
|
||||
if (isBinaryExpression(node)) {
|
||||
if (node.operatorToken.kind === SyntaxKind.EqualsToken) {
|
||||
const kind = node.left.kind;
|
||||
@@ -3522,6 +3528,7 @@ namespace ts {
|
||||
const exportSpecifiers = createMap<ExportSpecifier[]>();
|
||||
const exportedBindings = createMap<Identifier[]>();
|
||||
const uniqueExports = createMap<Identifier>();
|
||||
let hasExportDefault = false;
|
||||
let exportEquals: ExportAssignment = undefined;
|
||||
let hasExportStarsToExportValues = false;
|
||||
for (const node of sourceFile.statements) {
|
||||
@@ -3540,15 +3547,6 @@ namespace ts {
|
||||
externalImports.push(<ImportEqualsDeclaration>node);
|
||||
}
|
||||
|
||||
if (hasModifier(node, ModifierFlags.Export)) {
|
||||
// export import x = ...
|
||||
const name = (<ImportEqualsDeclaration>node).name;
|
||||
if (!uniqueExports[name.text]) {
|
||||
multiMapAdd(exportedBindings, getOriginalNodeId(node), name);
|
||||
uniqueExports[name.text] = name;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
@@ -3590,11 +3588,10 @@ namespace ts {
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
// export var x
|
||||
case SyntaxKind.VariableStatement:
|
||||
if (hasModifier(node, ModifierFlags.Export)) {
|
||||
for (const decl of (<VariableStatement>node).declarationList.declarations) {
|
||||
collectExportedVariableInfo(decl, exportedBindings, uniqueExports);
|
||||
collectExportedVariableInfo(decl, uniqueExports);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -3603,9 +3600,9 @@ namespace ts {
|
||||
if (hasModifier(node, ModifierFlags.Export)) {
|
||||
if (hasModifier(node, ModifierFlags.Default)) {
|
||||
// export default function() { }
|
||||
if (!uniqueExports["default"]) {
|
||||
if (!hasExportDefault) {
|
||||
multiMapAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(<FunctionDeclaration>node));
|
||||
uniqueExports["default"] = createIdentifier("default");
|
||||
hasExportDefault = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -3623,8 +3620,9 @@ namespace ts {
|
||||
if (hasModifier(node, ModifierFlags.Export)) {
|
||||
if (hasModifier(node, ModifierFlags.Default)) {
|
||||
// export default class { }
|
||||
if (!uniqueExports["default"]) {
|
||||
if (!hasExportDefault) {
|
||||
multiMapAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(<ClassDeclaration>node));
|
||||
hasExportDefault = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -3640,25 +3638,24 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
const exportedNames: Identifier[] = [];
|
||||
let exportedNames: Identifier[];
|
||||
for (const key in uniqueExports) {
|
||||
exportedNames.push(uniqueExports[key]);
|
||||
exportedNames = ts.append(exportedNames, uniqueExports[key]);
|
||||
}
|
||||
|
||||
return { externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues, exportedBindings, exportedNames };
|
||||
}
|
||||
|
||||
function collectExportedVariableInfo(decl: VariableDeclaration | BindingElement, exportedNames: Map<Identifier[]>, uniqueExports: Map<Identifier>) {
|
||||
function collectExportedVariableInfo(decl: VariableDeclaration | BindingElement, uniqueExports: Map<Identifier>) {
|
||||
if (isBindingPattern(decl.name)) {
|
||||
for (const element of decl.name.elements) {
|
||||
if (!isOmittedExpression(element)) {
|
||||
collectExportedVariableInfo(element, exportedNames, uniqueExports);
|
||||
collectExportedVariableInfo(element, uniqueExports);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!isGeneratedIdentifier(decl.name)) {
|
||||
if (!uniqueExports[decl.name.text]) {
|
||||
multiMapAdd(exportedNames, getOriginalNodeId(decl), decl.name);
|
||||
uniqueExports[decl.name.text] = decl.name;
|
||||
}
|
||||
}
|
||||
@@ -3901,6 +3898,14 @@ namespace ts {
|
||||
|
||||
// Expression
|
||||
|
||||
export function isArrayLiteralExpression(node: Node): node is ArrayLiteralExpression {
|
||||
return node.kind === SyntaxKind.ArrayLiteralExpression;
|
||||
}
|
||||
|
||||
export function isObjectLiteralExpression(node: Node): node is ObjectLiteralExpression {
|
||||
return node.kind === SyntaxKind.ObjectLiteralExpression;
|
||||
}
|
||||
|
||||
export function isPropertyAccessExpression(node: Node): node is PropertyAccessExpression {
|
||||
return node.kind === SyntaxKind.PropertyAccessExpression;
|
||||
}
|
||||
@@ -4161,7 +4166,8 @@ namespace ts {
|
||||
|| kind === SyntaxKind.WhileStatement
|
||||
|| kind === SyntaxKind.WithStatement
|
||||
|| kind === SyntaxKind.NotEmittedStatement
|
||||
|| kind === SyntaxKind.EndOfDeclarationMarker;
|
||||
|| kind === SyntaxKind.EndOfDeclarationMarker
|
||||
|| kind === SyntaxKind.MergeDeclarationMarker;
|
||||
}
|
||||
|
||||
export function isDeclaration(node: Node): node is Declaration {
|
||||
|
||||
@@ -151,13 +151,13 @@ System.register([], function (exports_1, context_1) {
|
||||
function exportedFoo() {
|
||||
return v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8;
|
||||
}
|
||||
exports_1("exportedFoo", exportedFoo);
|
||||
//======const
|
||||
function exportedFoo2() {
|
||||
return v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c + v8_c;
|
||||
}
|
||||
var v0, v00, v1, v2, v3, v4, v5, v6, v7, v8, v0_c, v00_c, v1_c, v2_c, v3_c, v4_c, v5_c, v6_c, v7_c, v8_c;
|
||||
exports_1("exportedFoo", exportedFoo);
|
||||
exports_1("exportedFoo2", exportedFoo2);
|
||||
var v0, v00, v1, v2, v3, v4, v5, v6, v7, v8, v0_c, v00_c, v1_c, v2_c, v3_c, v4_c, v5_c, v6_c, v7_c, v8_c;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
|
||||
@@ -14,8 +14,8 @@ System.register([], function (exports_1, context_1) {
|
||||
function bar() {
|
||||
return A.B.C.foo();
|
||||
}
|
||||
var A;
|
||||
exports_1("bar", bar);
|
||||
var A;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
|
||||
@@ -15,8 +15,8 @@ System.register("b", ["a"], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
function foo() { new a_1.default(); }
|
||||
var a_1;
|
||||
exports_1("default", foo);
|
||||
var a_1;
|
||||
return {
|
||||
setters: [
|
||||
function (a_1_1) {
|
||||
|
||||
@@ -24,10 +24,10 @@ System.register(["file1", "file2"], function (exports_1, context_1) {
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
exports_1("x", file1_1.x);
|
||||
exports_1("y", file1_1.x);
|
||||
exports_1("n", file1_1["default"]);
|
||||
exports_1("n1", file1_1["default"]);
|
||||
exports_1("x", file1_1.x);
|
||||
exports_1("y", file1_1.x);
|
||||
exports_1("n2", n2);
|
||||
exports_1("n3", n2);
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ System.register(["file1", "file2"], function (exports_1, context_1) {
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
exports_1("x", file1_1.x);
|
||||
exports_1("y", file1_1.x);
|
||||
exports_1("n", file1_1.default);
|
||||
exports_1("n1", file1_1.default);
|
||||
exports_1("x", file1_1.x);
|
||||
exports_1("y", file1_1.x);
|
||||
exports_1("n2", n2);
|
||||
exports_1("n3", n2);
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ System.register(["bar"], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
function foo() { }
|
||||
var x;
|
||||
exports_1("foo", foo);
|
||||
var x;
|
||||
var exportedNames_1 = {
|
||||
"x": true,
|
||||
"foo": true
|
||||
@@ -95,8 +95,6 @@ System.register(["bar"], function (exports_1, context_1) {
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
exports_1("x", x);
|
||||
exports_1("y1", y);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -139,10 +137,10 @@ System.register(["a"], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
function foo() { }
|
||||
function default_1() { }
|
||||
var x, z, z1;
|
||||
exports_1("foo", foo);
|
||||
function default_1() { }
|
||||
exports_1("default", default_1);
|
||||
var x, z, z1;
|
||||
return {
|
||||
setters: [
|
||||
function (a_1_1) {
|
||||
@@ -153,8 +151,6 @@ System.register(["a"], function (exports_1, context_1) {
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
exports_1("z", z);
|
||||
exports_1("z2", z1);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -8,12 +8,12 @@ for ([x] of [[1]]) {}
|
||||
System.register([], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var x, y, z, _a, z0, z1, _b;
|
||||
var x, y, z, z0, z1, _a, _b;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
_a = [1, 2, 3], exports_1("x", x = _a[0]), exports_1("y", y = _a[1]), exports_1("z", z = _a[2]);
|
||||
_b = { a: true, b: { c: "123" } }, exports_1("z0", z0 = _b.a), exports_1("z1", z1 = _b.b.c);
|
||||
exports_1("x", x = (_a = [1, 2, 3], _a[0])), exports_1("y", y = _a[1]), exports_1("z", z = _a[2]);
|
||||
exports_1("z0", z0 = (_b = { a: true, b: { c: "123" } }, _b.a)), exports_1("z1", z1 = _b.b.c);
|
||||
for (var _i = 0, _a = [[1]]; _i < _a.length; _i++) {
|
||||
exports_1("x", x = _a[_i][0]);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ System.register(["foo"], function (exports_1, context_1) {
|
||||
function foo() {
|
||||
return foo_1.a;
|
||||
}
|
||||
exports_1("foo", foo);
|
||||
exports_1("b", foo);
|
||||
var foo_1, x;
|
||||
return {
|
||||
setters: [
|
||||
@@ -25,9 +27,7 @@ System.register(["foo"], function (exports_1, context_1) {
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
exports_1("foo", foo);
|
||||
x = 1;
|
||||
exports_1("b", foo);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -71,18 +71,18 @@ System.register(["f1"], function (exports_1, context_1) {
|
||||
],
|
||||
execute: function () {
|
||||
x = 1;
|
||||
exports_1("x", x);
|
||||
exports_1("x1", x);
|
||||
(function (N) {
|
||||
N.x = 1;
|
||||
})(N || (N = {}));
|
||||
IX = N.x;
|
||||
exports_1("x", x);
|
||||
exports_1("x1", x);
|
||||
exports_1("IX", IX);
|
||||
exports_1("IX1", IX);
|
||||
exports_1("A", f1_1.A);
|
||||
exports_1("A1", f1_1.A);
|
||||
exports_1("EA", f1_1.A);
|
||||
exports_1("EA1", f1_1.A);
|
||||
exports_1("IX", IX);
|
||||
exports_1("IX1", IX);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -67,9 +67,9 @@ System.register([], function (exports_1, context_1) {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
default_1 = (function () {
|
||||
function class_1() {
|
||||
function default_1() {
|
||||
}
|
||||
return class_1;
|
||||
return default_1;
|
||||
}());
|
||||
exports_1("default", default_1);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ System.register([], function (exports_1, context_1) {
|
||||
for (exports_1("x", x = 18);; exports_1("x", --x)) { }
|
||||
for (var x_1 = 50;;) { }
|
||||
exports_1("y", y = [1][0]);
|
||||
_a = { a: true, b: { c: "123" } }, exports_1("z0", z0 = _a.a), exports_1("z1", z1 = _a.b.c);
|
||||
exports_1("z0", z0 = (_a = { a: true, b: { c: "123" } }, _a.a)), exports_1("z1", z1 = _a.b.c);
|
||||
for (var _i = 0, _a = [[1]]; _i < _a.length; _i++) {
|
||||
exports_1("x", x = _a[_i][0]);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ System.register(["file1", "file2", "file3", "file4", "file5", "file6", "file7"],
|
||||
ns2.f();
|
||||
ns3.f();
|
||||
y = true;
|
||||
exports_1("x", x);
|
||||
exports_1("z", y);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,8 +20,8 @@ System.register([], function (exports_1, context_1) {
|
||||
use(TopLevelConstEnum.X);
|
||||
use(M.NonTopLevelConstEnum.X);
|
||||
}
|
||||
var TopLevelConstEnum, M;
|
||||
exports_1("foo", foo);
|
||||
var TopLevelConstEnum, M;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
|
||||
@@ -14,8 +14,8 @@ System.register([], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
function F() { }
|
||||
var C, E;
|
||||
exports_1("F", F);
|
||||
var C, E;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
|
||||
@@ -48,9 +48,9 @@ System.register([], function (exports_1, context_1) {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
default_1 = (function () {
|
||||
function class_1() {
|
||||
function default_1() {
|
||||
}
|
||||
return class_1;
|
||||
return default_1;
|
||||
}());
|
||||
exports_1("default", default_1);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ System.register([], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
function TopLevelFunction() { }
|
||||
var TopLevelClass, TopLevelModule, TopLevelEnum, TopLevelModule2;
|
||||
exports_1("TopLevelFunction", TopLevelFunction);
|
||||
var TopLevelClass, TopLevelModule, TopLevelEnum, TopLevelModule2;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
|
||||
@@ -20,12 +20,12 @@ System.register([], function (exports_1, context_1) {
|
||||
function myFunction() {
|
||||
return new MyClass();
|
||||
}
|
||||
exports_1("myFunction", myFunction);
|
||||
function myFunction2() {
|
||||
return new MyClass2();
|
||||
}
|
||||
var MyClass, MyClass2;
|
||||
exports_1("myFunction", myFunction);
|
||||
exports_1("myFunction2", myFunction2);
|
||||
var MyClass, MyClass2;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
@@ -35,8 +35,8 @@ System.register([], function (exports_1, context_1) {
|
||||
MyClass2 = class MyClass2 {
|
||||
static getInstance() { return MyClass2.value; }
|
||||
};
|
||||
exports_1("MyClass2", MyClass2);
|
||||
MyClass2.value = 42;
|
||||
exports_1("MyClass2", MyClass2);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user