Skip to content

Commit ba9181c

Browse files
committed
Merge branch 'transforms-visitor' into transforms-flags
2 parents cadda66 + 8bf176a commit ba9181c

77 files changed

Lines changed: 3101 additions & 3188 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/compiler/binder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,9 @@ namespace ts {
17341734
case Reachability.Unreachable:
17351735
const reportError =
17361736
// report error on all statements except empty ones
1737-
(isStatement(node) && node.kind !== SyntaxKind.EmptyStatement) ||
1737+
(isStatementButNotDeclaration(node) && node.kind !== SyntaxKind.EmptyStatement) ||
1738+
// report error on ExportAssignment
1739+
node.kind === SyntaxKind.ExportAssignment ||
17381740
// report error on class declarations
17391741
node.kind === SyntaxKind.ClassDeclaration ||
17401742
// report error on instantiated modules or const-enums only modules if preserveConstEnums is set

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4934,7 +4934,7 @@ namespace ts {
49344934
case SyntaxKind.JSDocRecordType:
49354935
return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
49364936
// This function assumes that an identifier or qualified name is a type expression
4937-
// Callers should first ensure this by calling isTypeNode
4937+
// Callers should first ensure this by calling isPartOfTypeNode
49384938
case SyntaxKind.Identifier:
49394939
case SyntaxKind.QualifiedName:
49404940
const symbol = getSymbolAtLocation(node);
@@ -15385,7 +15385,7 @@ namespace ts {
1538515385
(entityName.parent.kind === SyntaxKind.JsxClosingElement)) {
1538615386
return getJsxElementTagSymbol(<JsxOpeningLikeElement>entityName.parent);
1538715387
}
15388-
else if (isExpression(entityName)) {
15388+
else if (isPartOfExpression(entityName)) {
1538915389
if (nodeIsMissing(entityName)) {
1539015390
// Missing entity name.
1539115391
return undefined;
@@ -15468,7 +15468,7 @@ namespace ts {
1546815468

1546915469
case SyntaxKind.ThisKeyword:
1547015470
case SyntaxKind.SuperKeyword:
15471-
const type = isExpression(node) ? checkExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node);
15471+
const type = isPartOfExpression(node) ? checkExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node);
1547215472
return type.symbol;
1547315473

1547415474
case SyntaxKind.ThisType:
@@ -15529,11 +15529,11 @@ namespace ts {
1552915529
return unknownType;
1553015530
}
1553115531

15532-
if (isTypeNode(node)) {
15532+
if (isPartOfTypeNode(node)) {
1553315533
return getTypeFromTypeNode(<TypeNode>node);
1553415534
}
1553515535

15536-
if (isExpression(node)) {
15536+
if (isPartOfExpression(node)) {
1553715537
return getTypeOfExpression(<Expression>node);
1553815538
}
1553915539

src/compiler/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ namespace ts {
868868
this.transformFlags = undefined;
869869
this.excludeTransformFlags = undefined;
870870
this.parent = undefined;
871+
this.original = undefined;
871872
}
872873

873874
export let objectAllocator: ObjectAllocator = {

src/compiler/emitter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10201020
return;
10211021
}
10221022

1023-
const emitOuterParens = isExpression(node.parent)
1023+
const emitOuterParens = isPartOfExpression(node.parent)
10241024
&& templateNeedsParens(node, <Expression>node.parent);
10251025

10261026
if (emitOuterParens) {
@@ -5788,7 +5788,7 @@ const _super = (function (geti, seti) {
57885788
/** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */
57895789
function emitSerializedTypeReferenceNode(node: TypeReferenceNode) {
57905790
let location: Node = node.parent;
5791-
while (isDeclaration(location) || isTypeNode(location)) {
5791+
while (isDeclaration(location) || isPartOfTypeNode(location)) {
57925792
location = location.parent;
57935793
}
57945794

@@ -7156,7 +7156,7 @@ const _super = (function (geti, seti) {
71567156
}
71577157

71587158
// text should be quoted string
7159-
// for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same
7159+
// for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same
71607160
const key = text.substr(1, text.length - 2);
71617161

71627162
if (hasProperty(groupIndices, key)) {

src/compiler/factory.ts

Lines changed: 97 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,138 @@
1-
/// <reference path="types.ts"/>
1+
/// <reference path="core.ts"/>
22
/// <reference path="utilities.ts"/>
3-
/* @internal */
3+
44
namespace ts {
5-
export function createNodeArray<T extends Node>(elements?: T[], location?: TextRange): NodeArray<T>;
6-
export function createNodeArray<T extends Node, TArray extends NodeArray<T>>(elements: TArray, location?: TextRange): TArray;
7-
export function createNodeArray<T extends Node, TArray extends NodeArray<T>>(elements?: T[], location?: TextRange): TArray {
8-
const array = <TArray>(elements || []);
9-
if (location) {
10-
array.pos = location.pos;
11-
array.end = location.end;
5+
let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
6+
let SourceFileConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
7+
8+
export function createNode(kind: SyntaxKind, pos?: number, end?: number): Node {
9+
if (kind === SyntaxKind.SourceFile) {
10+
return new (SourceFileConstructor || (SourceFileConstructor = objectAllocator.getSourceFileConstructor()))(kind, pos, end);
1211
}
13-
else if (array.pos === undefined || array.end === undefined) {
14-
array.pos = -1;
15-
array.end = -1;
12+
else {
13+
return new (NodeConstructor || (NodeConstructor = objectAllocator.getNodeConstructor()))(kind, pos, end);
1614
}
15+
}
1716

17+
/* @internal */
18+
export function createNodeArray<T extends Node>(elements?: T[], pos?: number, end?: number): NodeArray<T> {
19+
const array = <NodeArray<T>>(elements || []);
20+
array.pos = pos;
21+
array.end = end;
22+
array.arrayKind = ArrayKind.NodeArray;
1823
return array;
1924
}
2025

21-
export function createNodeArrayNode<T extends Node>(elements?: (T | NodeArrayNode<T>)[]): NodeArrayNode<T> {
22-
const array = <NodeArrayNode<T>>createNodeArray(elements);
23-
array.kind = SyntaxKind.NodeArrayNode;
26+
/* @internal */
27+
export function createModifiersArray(elements?: Modifier[], pos?: number, end?: number): ModifiersArray {
28+
const array = <ModifiersArray>(elements || []);
29+
array.pos = pos;
30+
array.end = end;
31+
array.arrayKind = ArrayKind.ModifiersArray;
32+
array.flags = 0;
2433
return array;
2534
}
2635

36+
/* @internal */
37+
export function createSynthesizedNode(kind: SyntaxKind, startsOnNewLine?: boolean): Node {
38+
const node = <SynthesizedNode>createNode(kind, /*pos*/ -1, /*end*/ -1);
39+
node.startsOnNewLine = startsOnNewLine;
40+
return node;
41+
}
42+
43+
/* @internal */
44+
export function createSynthesizedNodeArray<T extends Node>(elements?: T[]): NodeArray<T> {
45+
return createNodeArray(elements, /*pos*/ -1, /*end*/ -1);
46+
}
47+
48+
/* @internal */
49+
export function createSynthesizedModifiersArray(elements?: Modifier[]): ModifiersArray {
50+
return createModifiersArray(elements, /*pos*/ -1, /*end*/ -1);
51+
}
52+
53+
/**
54+
* Creates a shallow, memberwise clone of a node. The "kind", "pos", "end", "flags", and "parent"
55+
* properties are excluded by default, and can be provided via the "location", "flags", and
56+
* "parent" parameters.
57+
*
58+
* @param node The node to clone.
59+
* @param location An optional TextRange to use to supply the new position.
60+
* @param flags The NodeFlags to use for the cloned node.
61+
* @param parent The parent for the new node.
62+
* @param original An optional pointer to the original source tree node.
63+
*/
64+
/* @internal */
65+
export function cloneNode<T extends Node>(node: T, location?: TextRange, flags?: NodeFlags, parent?: Node, original?: Node): T {
66+
// We don't use "clone" from core.ts here, as we need to preserve the prototype chain of
67+
// the original node. We also need to exclude specific properties and only include own-
68+
// properties (to skip members already defined on the shared prototype).
69+
const clone = location !== undefined
70+
? <T>createNode(node.kind, location.pos, location.end)
71+
: <T>createSynthesizedNode(node.kind);
72+
73+
for (const key in node) {
74+
if (clone.hasOwnProperty(key) || !node.hasOwnProperty(key)) {
75+
continue;
76+
}
77+
78+
(<any>clone)[key] = (<any>node)[key];
79+
}
80+
81+
if (flags !== undefined) {
82+
clone.flags = flags;
83+
}
84+
85+
if (parent !== undefined) {
86+
clone.parent = parent;
87+
}
88+
89+
if (original !== undefined) {
90+
clone.original = original;
91+
}
92+
93+
return clone;
94+
}
95+
96+
/* @internal */
97+
export function createNodeArrayNode<T extends Node>(elements: T[]): NodeArrayNode<T> {
98+
const node = <NodeArrayNode<T>>createSynthesizedNode(SyntaxKind.NodeArrayNode);
99+
node.nodes = createNodeArray(elements);
100+
return node;
101+
}
102+
103+
/* @internal */
27104
export function createReturn(expression?: Expression): ReturnStatement {
28105
const node = <ReturnStatement>createSynthesizedNode(SyntaxKind.ReturnStatement);
29106
node.expression = expression;
30107
return node;
31108
}
32109

110+
/* @internal */
33111
export function createStatement(expression: Expression): ExpressionStatement {
34112
const node = <ExpressionStatement>createSynthesizedNode(SyntaxKind.ExpressionStatement);
35113
node.expression = expression;
36114
return node;
37115
}
38116

117+
/* @internal */
39118
export function createVariableStatement(declarationList: VariableDeclarationList): VariableStatement {
40119
const node = <VariableStatement>createSynthesizedNode(SyntaxKind.VariableStatement);
41120
node.declarationList = declarationList;
42121
return node;
43122
}
44123

124+
/* @internal */
45125
export function createVariableDeclarationList(declarations: VariableDeclaration[]): VariableDeclarationList {
46126
const node = <VariableDeclarationList>createSynthesizedNode(SyntaxKind.VariableDeclarationList);
47127
node.declarations = createNodeArray(declarations);
48128
return node;
49129
}
50130

131+
/* @internal */
51132
export function createBlock(statements: Statement[]): Block {
52133
const block = <Block>createSynthesizedNode(SyntaxKind.Block);
53134
block.statements = createNodeArray(statements);
54135
return block;
55136
}
137+
56138
}

0 commit comments

Comments
 (0)