mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 20:25:23 -06:00
Adds a NodeFlag to indicate a synthetic node.
This commit is contained in:
parent
96ba0f2696
commit
e5c473c9fc
@ -17,9 +17,7 @@ namespace ts {
|
||||
? new ConstructorForKind(kind, location.pos, location.end)
|
||||
: new ConstructorForKind(kind, /*pos*/ -1, /*end*/ -1);
|
||||
|
||||
if (flags) {
|
||||
node.flags = flags;
|
||||
}
|
||||
node.flags = flags | NodeFlags.Synthesized;
|
||||
|
||||
return node;
|
||||
}
|
||||
@ -68,8 +66,7 @@ namespace ts {
|
||||
// We don't use "clone" from core.ts here, as we need to preserve the prototype chain of
|
||||
// the original node. We also need to exclude specific properties and only include own-
|
||||
// properties (to skip members already defined on the shared prototype).
|
||||
const clone = <T>createNode(node.kind, /*location*/ undefined, /*flags*/ undefined);
|
||||
clone.flags = node.flags;
|
||||
const clone = <T>createNode(node.kind, /*location*/ undefined, node.flags);
|
||||
clone.original = node;
|
||||
|
||||
for (const key in node) {
|
||||
@ -827,6 +824,7 @@ namespace ts {
|
||||
// Create an identifier and give it a parent. This allows us to resolve the react
|
||||
// namespace during emit.
|
||||
const react = createIdentifier(reactNamespace || "React");
|
||||
react.flags &= ~NodeFlags.Synthesized;
|
||||
react.parent = parent;
|
||||
return react;
|
||||
}
|
||||
|
||||
@ -2034,7 +2034,7 @@ namespace ts {
|
||||
// FormalParameter [Yield,Await]:
|
||||
// BindingElement[?Yield,?Await]
|
||||
node.name = parseIdentifierOrPattern();
|
||||
if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifierKind(token)) {
|
||||
if (getFullWidth(node.name) === 0 && !hasModifiers(node) && isModifierKind(token)) {
|
||||
// in cases like
|
||||
// 'use strict'
|
||||
// function foo(static)
|
||||
|
||||
@ -1752,7 +1752,10 @@ namespace ts {
|
||||
function serializeEntityNameAsExpression(node: EntityName, useFallback: boolean): Expression {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
// Create a clone of the name with a new parent, and treat it as if it were
|
||||
// a source tree node for the purposes of the checker.
|
||||
const name = getMutableClone(<Identifier>node);
|
||||
name.flags &= ~NodeFlags.Synthesized;
|
||||
name.original = undefined;
|
||||
name.parent = currentScope;
|
||||
if (useFallback) {
|
||||
|
||||
@ -383,6 +383,7 @@ namespace ts {
|
||||
Let = 1 << 0, // Variable declaration
|
||||
Const = 1 << 1, // Variable declaration
|
||||
NestedNamespace = 1 << 2, // Namespace declaration
|
||||
Synthesized = 1 << 3, // Node was synthesized during transformation
|
||||
Namespace = 1 << 12, // Namespace declaration
|
||||
ExportContext = 1 << 13, // Export context (initialized by binding)
|
||||
ContainsThis = 1 << 14, // Interface contains references to "this"
|
||||
|
||||
@ -1831,14 +1831,17 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function isSourceTreeNode(node: Node): boolean {
|
||||
return node.original === undefined
|
||||
&& (node.parent !== undefined || node.kind === SyntaxKind.SourceFile);
|
||||
return (node.flags & NodeFlags.Synthesized) === 0;
|
||||
}
|
||||
|
||||
export function getSourceTreeNode(node: Node): Node {
|
||||
if (isSourceTreeNode(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
node = getOriginalNode(node);
|
||||
|
||||
if (node && (node.parent !== undefined || node.kind === SyntaxKind.SourceFile)) {
|
||||
if (isSourceTreeNode(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user