-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Adds the Transform Flags concept for tree transformations #6983
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
cadda66
ba9181c
1e35593
34489a4
cbb910a
1a0b877
51dd27a
6fa4002
0f2bbb1
6b381ec
fb19e81
e545f1b
49d2d93
f948b14
4577441
319ff61
ceae78b
f8ed021
ab811f9
c634a36
0f16e68
8ec3932
357171f
c4dc2ae
6c0551f
1ceb02a
dd2dc78
c759b63
39628d7
5564537
ab8e83e
cd7c229
024eff1
11d54ba
2ab8877
8e0d28e
80f89a1
7d72c18
90a317f
6d27336
f52a30b
64e7aa8
0a325ee
3d8cb51
0145009
dc0b043
0b64048
f3179da
617e511
61fe61b
c166a2d
5b7bd63
6d111e3
4a81dde
2e47e2e
e5cd8fe
b3adade
61f3ba6
ad314b0
0937cec
98ab964
52c62d0
f484ff4
635347e
9871d3b
de9866f
02b85f8
f92c24b
40b61fb
4f03b31
75b2181
951ce55
08036b7
608822d
c9f5253
25f4102
cde3b34
5a9b131
78dfab8
0d8e152
72bfd2f
cd2cf7d
b1d8828
8e5e5f8
359875b
fe7ad5f
a0dbe76
a7f9cda
7d05ba2
186f5c8
2c9cd2e
88e1772
30433c2
2d2709f
70cbb9b
ebb4764
e66e51d
8b35af4
1fdaf74
593fbd4
7b28b48
1c73818
c4a75ba
72eebdb
1cf183b
d89e21a
5b8cf96
99e6ad8
47cdfbe
2699bf9
94018a1
ad0dd4e
44ca7d4
ae7843d
3c5f170
07a3d18
cc00f4c
829a9df
ca9148e
85ae53d
a212e2b
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 |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ namespace ts { | |
| return ModuleInstanceState.ConstEnumOnly; | ||
| } | ||
| // 3. non-exported import declarations | ||
| else if ((node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) && !(node.flags & NodeFlags.Export)) { | ||
| else if ((node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) && !(getModifierFlags(node) & ModifierFlags.Export)) { | ||
| return ModuleInstanceState.NonInstantiated; | ||
| } | ||
| // 4. other uninstantiated module declarations. | ||
|
|
@@ -256,7 +256,7 @@ namespace ts { | |
|
|
||
| case SyntaxKind.FunctionDeclaration: | ||
| case SyntaxKind.ClassDeclaration: | ||
| return node.flags & NodeFlags.Default ? "default" : undefined; | ||
| return getModifierFlags(node) & ModifierFlags.Default ? "default" : undefined; | ||
| case SyntaxKind.JSDocFunctionType: | ||
| return isJSDocConstructSignature(node) ? "__new" : "__call"; | ||
| case SyntaxKind.Parameter: | ||
|
|
@@ -284,7 +284,7 @@ namespace ts { | |
| function declareSymbol(symbolTable: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol { | ||
| Debug.assert(!hasDynamicName(node)); | ||
|
|
||
| const isDefaultExport = node.flags & NodeFlags.Default; | ||
| const isDefaultExport = getModifierFlags(node) & ModifierFlags.Default; | ||
| // The exported symbol for an export default function/class node is always named "default" | ||
| const name = isDefaultExport && parent ? "default" : getDeclarationName(node); | ||
|
|
||
|
|
@@ -329,7 +329,7 @@ namespace ts { | |
| : Diagnostics.Duplicate_identifier_0; | ||
|
|
||
| forEach(symbol.declarations, declaration => { | ||
| if (declaration.flags & NodeFlags.Default) { | ||
| if (getModifierFlags(declaration) & ModifierFlags.Default) { | ||
| message = Diagnostics.A_module_cannot_have_multiple_default_exports; | ||
| } | ||
| }); | ||
|
|
@@ -353,7 +353,7 @@ namespace ts { | |
| } | ||
|
|
||
| function declareModuleMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol { | ||
| const hasExportModifier = getCombinedNodeFlags(node) & NodeFlags.Export; | ||
| const hasExportModifier = getCombinedModifierFlags(node) & ModifierFlags.Export; | ||
| if (symbolFlags & SymbolFlags.Alias) { | ||
| if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && hasExportModifier)) { | ||
| return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); | ||
|
|
@@ -862,7 +862,7 @@ namespace ts { | |
| } | ||
|
|
||
| function declareClassMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { | ||
| return node.flags & NodeFlags.Static | ||
| return getModifierFlags(node) & ModifierFlags.Static | ||
| ? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes) | ||
| : declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); | ||
| } | ||
|
|
@@ -899,7 +899,7 @@ namespace ts { | |
| function bindModuleDeclaration(node: ModuleDeclaration) { | ||
| setExportContextFlag(node); | ||
| if (isAmbientModule(node)) { | ||
| if (node.flags & NodeFlags.Export) { | ||
| if (getModifierFlags(node) & ModifierFlags.Export) { | ||
| errorOnFirstToken(node, Diagnostics.export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible); | ||
| } | ||
| declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes); | ||
|
|
@@ -1800,7 +1800,7 @@ namespace ts { | |
| */ | ||
| export function computeTransformFlagsForNode(node: Node, subtreeFlags: TransformFlags): TransformFlags { | ||
| // Ambient nodes are TypeScript syntax and the flags of their subtree are ignored. | ||
| if (node.flags & NodeFlags.Ambient) { | ||
| if (getModifierFlags(node) & ModifierFlags.Ambient) { | ||
| return (node.transformFlags = TransformFlags.AssertTypeScript) | ||
| & ~(node.excludeTransformFlags = TransformFlags.NodeExcludes); | ||
| } | ||
|
|
@@ -2008,7 +2008,7 @@ namespace ts { | |
| } | ||
|
|
||
| // If a parameter has an accessibility modifier, then it is TypeScript syntax. | ||
| if ((<ParameterDeclaration>node).flags & NodeFlags.AccessibilityModifier) { | ||
| if (getModifierFlags(node) & ModifierFlags.AccessibilityModifier) { | ||
| transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.ContainsParameterPropertyAssignments; | ||
| } | ||
|
|
||
|
|
@@ -2033,7 +2033,7 @@ namespace ts { | |
| } | ||
|
|
||
| // An async arrow function is TypeScript syntax. | ||
| if (node.flags & NodeFlags.Async) { | ||
| if (getModifierFlags(node) & ModifierFlags.Async) { | ||
| transformFlags |= TransformFlags.AssertTypeScript; | ||
| } | ||
|
|
||
|
|
@@ -2052,7 +2052,7 @@ namespace ts { | |
| } | ||
|
|
||
| // An async function expression is TypeScript syntax. | ||
| if (node.flags & NodeFlags.Async) { | ||
| if (getModifierFlags(node) & ModifierFlags.Async) { | ||
| transformFlags |= TransformFlags.AssertTypeScript; | ||
| } | ||
|
|
||
|
|
@@ -2072,14 +2072,14 @@ namespace ts { | |
| // subtree has marked the container as needing to capture the lexical `this`, | ||
| // then this node is ES6 syntax. | ||
| if ((<FunctionDeclaration>node).asteriskToken | ||
| || node.flags & NodeFlags.Export | ||
| || getModifierFlags(node) & ModifierFlags.Export | ||
| || subtreeFlags & TransformFlags.ContainsCapturedLexicalThis | ||
| || subtreeFlags & TransformFlags.ContainsDefaultValueAssignments) { | ||
| transformFlags |= TransformFlags.AssertES6; | ||
| } | ||
|
|
||
| // An async function declaration is TypeScript syntax. | ||
| if (node.flags & NodeFlags.Async) { | ||
| if (getModifierFlags(node) & ModifierFlags.Async) { | ||
| transformFlags |= TransformFlags.AssertTypeScript; | ||
| } | ||
|
|
||
|
|
@@ -2103,7 +2103,7 @@ namespace ts { | |
|
|
||
| case SyntaxKind.VariableStatement: | ||
| // If a VariableStatement is exported, then it is either ES6 or TypeScript syntax. | ||
| if (node.flags & NodeFlags.Export) { | ||
| if (getModifierFlags(node) & ModifierFlags.Export) { | ||
| transformFlags |= TransformFlags.AssertES6 | TransformFlags.AssertTypeScript; | ||
| } | ||
|
|
||
|
|
@@ -2204,8 +2204,7 @@ namespace ts { | |
| // generic, or has both a computed property name and a decorator. | ||
| if ((<MethodDeclaration>node).body === undefined | ||
| || (<MethodDeclaration>node).typeParameters !== undefined | ||
| || node.flags & NodeFlags.Async | ||
| || node.flags & NodeFlags.Abstract | ||
| || getModifierFlags(node) & (ModifierFlags.Async | ModifierFlags.Abstract) | ||
| || (subtreeFlags & TransformFlags.ContainsDecorators | ||
| && subtreeFlags & TransformFlags.ContainsComputedPropertyName)) { | ||
|
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. why you care about
Contributor
Author
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. This has to do with decorators. We don't want to re-evaluate the expression of the computed property name: // ts
class C {
@dec
[generateRandomMethodName()]() {
}
}
// js
class C {
[_a = generateRandomMethodName()]() {
}
}
__decorate([dec], C.prototype, _a, null);
var _a;We need to flag the method itself as needing a specific transformation in this case, to transform the computed property name. |
||
| transformFlags |= TransformFlags.AssertTypeScript; | ||
|
|
@@ -2220,7 +2219,7 @@ namespace ts { | |
|
|
||
| // A GetAccessor or SetAccessor is TypeScript syntax if it is either abstract, | ||
| // or has both a computed property name and a decorator. | ||
| if (node.flags & NodeFlags.Abstract || | ||
| if (getModifierFlags(node) & ModifierFlags.Abstract || | ||
| subtreeFlags & TransformFlags.ContainsDecorators && | ||
| subtreeFlags & TransformFlags.ContainsComputedPropertyName) { | ||
|
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. why you care about ContainsComputedPropertyName to set the flag with AssertTypeScript?
Contributor
Author
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. See #6983 (comment) above for rationale. |
||
| transformFlags |= TransformFlags.AssertTypeScript; | ||
|
|
||
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.
Not sure I understand why there is 'tilde' here?
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.
Bitwise not?
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.
Yes,
~gets the ones-complement of the operand. The result here is thetransformFlagsof the node, excludingexcludeTransformFlagsof the 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.
Gotcha . Thanks @weswigham and @rbuckton. Also could you put return type in the signature?