-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[Transforms] Merge master 06/06/2016 #8991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
20d8a94
a2feb0e
92bf91d
73d4aae
70733da
a80529b
21587aa
0a277a1
060f2a8
7b0d664
4464a41
291ad33
e5a32b7
02f30ff
b9ab4d3
f657e3c
81ee968
63291d1
9a4b6ab
4e415eb
269ebda
ec60ac9
ebd4ce6
f1ac06f
eca9437
47eac4f
3b7814b
5d9c871
fa16a99
a0546a9
f4d6b67
d4b8889
9179f4c
d111a0f
9a620bf
9575b3c
0e96c5e
92177be
3b19825
2517238
5f3f2d3
706683d
4281bf5
9f087cb
20bab14
ef0f6c8
fb2df77
7e00d7e
d41ac8a
7e9cb46
fc3e040
e2a1a78
24f15a4
131f759
3853555
bcc9220
13698a9
094f97e
1541ebe
ed6bfcd
c8ced67
8b0974a
2bed32d
e412f52
baebf2b
3aaa4ea
39c4e8a
a5e9071
87ee72b
6dcd587
bb7818b
3b1effb
18a8758
f5ab9d7
2fc2f5c
f832488
543b484
13ddc34
447e583
d9ec512
e05e112
1cbcdaf
52138e0
f215ac9
a918730
cd1b9f0
704f987
9761c3b
26b1ab4
693cb9c
2918c18
1fe8a08
941c863
bfafecc
52d8a78
3052913
53a5b42
ed48e58
849ab7c
843aa6c
b4f1214
715ca12
5fef080
d941177
6913c32
37949a3
78792df
17cc206
8b7fb8e
6a243e3
cdf5b7a
cdf4cde
6bf5f11
65bbeb1
d694146
83971d0
9832f62
1fe6626
ea1bdff
a57ee29
404650d
97270ce
7eb5f4b
179d423
d8667ae
9027da4
899f667
cc5dd5b
d36d2b3
6b8109a
9fac99e
17b5415
de8ddd6
1ebb85a
5a0ae4a
8f39f05
7c1b28f
11377f9
454ab50
aeb1d97
b3c5c1d
d182a59
8360bc7
33137f6
6446827
e7954cc
f42d8b8
475c1c2
82505ea
f74a41a
19baf1f
8fc3422
b1a7498
c14d711
9e12290
0aa2fe3
b08fe6f
9ef9b74
59d27ed
c404ea7
75b8293
3ab1e27
d36d9a3
06300e2
7a2ef42
3492542
5e72b8a
03371c0
559b49b
3954e99
512c671
75c1d77
88be1ac
b521fd5
0c64b0c
302cea8
9fa9710
a88366d
9ffd00d
d0f669e
574a64d
e307295
a4991b9
a1e4b31
f0a430a
86a6959
2b46656
6923cba
5af8ba8
a1e4135
6687f2c
e6eb36e
ff6e025
d973f4d
077dfff
71b7d44
97d7aa5
5ae0602
72d64e1
b027b4f
ccd4552
81d1ccf
7a022ee
6153422
d4b0dc8
cbd72fc
9afb10c
64f875c
121ab44
fb050f1
6f63799
34c3f68
784b841
d44ae78
28014a2
abf33f6
e5a197f
8b09312
cad23ad
9c8aa62
d5d2f8c
9415385
55c5ab7
9752699
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,19 +26,24 @@ namespace ts { | |
| const languageVersion = getEmitScriptTarget(compilerOptions); | ||
| const moduleKind = getEmitModuleKind(compilerOptions); | ||
| const previousOnSubstituteNode = context.onSubstituteNode; | ||
| const previousOnEmitNode = context.onEmitNode; | ||
| context.onSubstituteNode = onSubstituteNode; | ||
| context.onEmitNode = onEmitNode; | ||
| context.enableSubstitution(SyntaxKind.Identifier); | ||
| context.enableSubstitution(SyntaxKind.BinaryExpression); | ||
| context.enableSubstitution(SyntaxKind.PrefixUnaryExpression); | ||
| context.enableSubstitution(SyntaxKind.PostfixUnaryExpression); | ||
| context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); | ||
| context.enableEmitNotification(SyntaxKind.SourceFile); | ||
|
|
||
| let currentSourceFile: SourceFile; | ||
| let externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; | ||
| let exportSpecifiers: Map<ExportSpecifier[]>; | ||
| let exportEquals: ExportAssignment; | ||
| // Subset of exportSpecifiers that is binding-name. This is to reduce amount of memory we have to keep around even after we done with module.ts transformer | ||
| let bindingNameExportSpecifiers: Map<Map<ExportSpecifier[]>>; | ||
| let currentSourceFileIdDuringSubstitution: number; | ||
| // Subset of exportSpecifiers that is a binding-name. | ||
| // This is to reduce amount of memory we have to keep around even after we done with module-transformer | ||
| let bindingNameExportSpecifiersForFileMap: Map<Map<ExportSpecifier[]>>; | ||
| let hasExportStarsToExportValues: boolean; | ||
|
|
||
| return transformSourceFile; | ||
|
|
@@ -659,14 +664,14 @@ namespace ts { | |
| } | ||
| else { | ||
| if (!exportEquals && exportSpecifiers && hasProperty(exportSpecifiers, name.text)) { | ||
| if (!bindingNameExportSpecifiers) { | ||
| bindingNameExportSpecifiers = {}; | ||
| if (!bindingNameExportSpecifiersForFileMap) { | ||
| bindingNameExportSpecifiersForFileMap = {}; | ||
| } | ||
| const sourceFileName = currentSourceFile.fileName; | ||
| if (!bindingNameExportSpecifiers[sourceFileName]) { | ||
| bindingNameExportSpecifiers[sourceFileName] = {}; | ||
| const sourceFileId = getOriginalNodeId(currentSourceFile); | ||
| if (!bindingNameExportSpecifiersForFileMap[sourceFileId]) { | ||
| bindingNameExportSpecifiersForFileMap[sourceFileId] = {}; | ||
| } | ||
| bindingNameExportSpecifiers[sourceFileName][name.text] = exportSpecifiers[name.text]; | ||
| bindingNameExportSpecifiersForFileMap[sourceFileId][name.text] = exportSpecifiers[name.text]; | ||
| addExportMemberAssignments(resultStatements, name); | ||
| } | ||
| } | ||
|
|
@@ -814,6 +819,18 @@ namespace ts { | |
| return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node); | ||
| } | ||
|
|
||
| function onEmitNode(node: Node, emit: (node: Node) => void): void { | ||
| if (node.kind === SyntaxKind.SourceFile) { | ||
| const savedCurrentSourceFileIdDuringSubstitution = currentSourceFileIdDuringSubstitution; | ||
| currentSourceFileIdDuringSubstitution = getOriginalNodeId(node); | ||
| previousOnEmitNode(node, emit); | ||
| currentSourceFileIdDuringSubstitution = savedCurrentSourceFileIdDuringSubstitution; | ||
| } | ||
| else { | ||
| previousOnEmitNode(node, emit); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Hooks node substitutions. | ||
| * | ||
|
|
@@ -871,12 +888,13 @@ namespace ts { | |
| const left = node.left; | ||
| // If the left-hand-side of the binaryExpression is an identifier and its is export through export Specifier | ||
| if (isIdentifier(left) && isAssignmentOperator(node.operatorToken.kind)) { | ||
| const sourceFile = getSourceFileOfNode(node); | ||
| const sourceFileName = sourceFile ? sourceFile.fileName : undefined; | ||
| if (bindingNameExportSpecifiers && bindingNameExportSpecifiers[sourceFileName] && hasProperty(bindingNameExportSpecifiers[sourceFileName], left.text)) { | ||
| if (bindingNameExportSpecifiersForFileMap && | ||
| bindingNameExportSpecifiersForFileMap[currentSourceFileIdDuringSubstitution] && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we store the result of this lookup in a local variable so we aren't performing the same lookup twice in a row? |
||
| hasProperty(bindingNameExportSpecifiersForFileMap[currentSourceFileIdDuringSubstitution], left.text)) { | ||
|
|
||
| setNodeEmitFlags(node, NodeEmitFlags.NoSubstitution); | ||
| let nestedExportAssignment: BinaryExpression; | ||
| for (const specifier of bindingNameExportSpecifiers[sourceFileName][left.text]) { | ||
| for (const specifier of bindingNameExportSpecifiersForFileMap[currentSourceFileIdDuringSubstitution][left.text]) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, use a local variable to hold this so we aren't performing the lookup a third time. |
||
| nestedExportAssignment = nestedExportAssignment ? | ||
| createExportAssignment(specifier.name, nestedExportAssignment) : | ||
| createExportAssignment(specifier.name, node); | ||
|
|
@@ -892,24 +910,25 @@ namespace ts { | |
| // We don't need to check that the operator has SyntaxKind.plusplus or SyntaxKind.minusminus | ||
| const operator = node.operator; | ||
| const operand = node.operand; | ||
| if (isIdentifier(operand) && bindingNameExportSpecifiers) { | ||
| const sourceFile = getSourceFileOfNode(node); | ||
| const sourceFileName = sourceFile ? sourceFile.fileName : undefined; | ||
| if (bindingNameExportSpecifiers && bindingNameExportSpecifiers[sourceFileName] && hasProperty(bindingNameExportSpecifiers[sourceFileName], operand.text)) { | ||
| if (isIdentifier(operand) && bindingNameExportSpecifiersForFileMap) { | ||
| if (bindingNameExportSpecifiersForFileMap && | ||
| bindingNameExportSpecifiersForFileMap[currentSourceFileIdDuringSubstitution] && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, create a local variable to hold this so we aren't performing the same lookup multiple times. |
||
| hasProperty(bindingNameExportSpecifiersForFileMap[currentSourceFileIdDuringSubstitution], operand.text)) { | ||
|
|
||
| setNodeEmitFlags(node, NodeEmitFlags.NoSubstitution); | ||
| let transformedUnaryExpression: BinaryExpression; | ||
| if (node.kind === SyntaxKind.PostfixUnaryExpression) { | ||
| transformedUnaryExpression = createBinaryWithOperatorToken( | ||
| operand, | ||
| createNode(operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusEqualsToken : SyntaxKind.MinusEqualsToken), | ||
| createIdentifier("1"), | ||
| /*location*/ node | ||
| createLiteral(1), | ||
| /*location*/ node | ||
| ); | ||
| // We have to set no substitution flag here to prevent visit the binary expression and substitute it again as we will preform all necessary substitution in here | ||
| setNodeEmitFlags(transformedUnaryExpression, NodeEmitFlags.NoSubstitution); | ||
| } | ||
| let nestedExportAssignment: BinaryExpression; | ||
| for (const specifier of bindingNameExportSpecifiers[sourceFileName][operand.text]) { | ||
| for (const specifier of bindingNameExportSpecifiersForFileMap[currentSourceFileIdDuringSubstitution][operand.text]) { | ||
| nestedExportAssignment = nestedExportAssignment ? | ||
| createExportAssignment(specifier.name, nestedExportAssignment) : | ||
| createExportAssignment(specifier.name, transformedUnaryExpression || node); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to enable emit notification for source files so that you know the current source file during substitution.