8000 Merge branch 'transforms-transformer-jsx' into transforms-transformer… · icssjs/TypeScript@2c9cd2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c9cd2e

Browse files
committed
Merge branch 'transforms-transformer-jsx' into transforms-transformer-es7
2 parents 5a9b131 + 186f5c8 commit 2c9cd2e

File tree

179 files changed

+1654
-1580
lines changed

Some content is hidden

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

179 files changed

+1654
-1580
lines changed

Jakefile.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ function concatenateFiles(destinationFile, sourceFiles) {
239239

240240
var useDebugMode = true;
241241
var useTransforms = process.env.USE_TRANSFORMS || false;
242-
var useTransformCompat = false;
243242
var host = (process.env.host || process.env.TYPESCRIPT_HOST || "node");
244243
var compilerFilename = "tsc.js";
245244
var LKGCompiler = path.join(LKGDirectory, compilerFilename);
@@ -302,9 +301,6 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
302301
if (useBuiltCompiler && useTransforms) {
303302
options += " --experimentalTransforms"
304303
}
305-
else if (useBuiltCompiler && useTransformCompat) {
306-
options += " --transformCompatibleEmit"
307-
}
308304

309305
var cmd = host + " " + compilerPath + " " + options + " ";
310306
cmd = cmd + sources.join(" ");
@@ -433,10 +429,6 @@ task("setTransforms", function() {
433429
useTransforms = true;
434430
});
435431

436-
task("setTransformCompat", function() {
437-
useTransformCompat = true;
438-
});
439-
440432
task("configure-nightly", [configureNightlyJs], function() {
441433
var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + programTs;
442434
console.log(cmd);

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4846,7 +4846,7 @@ namespace ts {
48464846
const parent = container && container.parent;
48474847
if (parent && (isClassLike(parent) || parent.kind === SyntaxKind.InterfaceDeclaration)) {
48484848
if (!(container.flags & NodeFlags.Static) &&
4849-
(container.kind !== SyntaxKind.Constructor || isNodeDescendentOf(node, (<ConstructorDeclaration>container).body))) {
4849+
(container.kind !== SyntaxKind.Constructor || isNodeDescendantOf(node, (<ConstructorDeclaration>container).body))) {
48504850
return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType;
48514851
}
48524852
}
@@ -7206,8 +7206,8 @@ namespace ts {
72067206
let container = getContainingClass(node);
72077207
while (container !== undefined) {
72087208
if (container === localOrExportSymbol.valueDeclaration && container.name !== node) {
7209-
getNodeLinks(container).flags |= NodeCheckFlags.ClassWithBodyScopedClassBinding;
7210-
getNodeLinks(node).flags |= NodeCheckFlags.BodyScopedClassBinding;
7209+
getNodeLinks(container).flags |= NodeCheckFlags.DecoratedClassWithSelfReference;
7210+
getNodeLinks(node).flags |= NodeCheckFlags.SelfReferenceInDecoratedClass;
72117211
break;
72127212
}
72137213

src/compiler/commandLineParser.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,6 @@ namespace ts {
327327
name: "experimentalTransforms",
328328
type: "boolean",
329329
experimental: true
330-
},
331-
{
332-
// this option will be removed when this is merged with master and exists solely
333-
// to enable the tree transforming emitter side-by-side with the existing emitter.
334-
name: "transformCompatibleEmit",
335-
type: "boolean",
336-
experimental: true
337330
}
338331
];
339332

src/compiler/core.ts

Lines changed: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,99 @@ namespace ts {
171171
return result;
172172
}
173173

174+
/**
175+
* Flattens an array containing a mix of array or non-array elements.
176+
*
177+
* @param array The array to flatten.
178+
*/
179+
export function flatten<T>(array: (T | T[])[]): T[] {
180+
let result: T[];
181+
if (array) {
182+
result = [];
183+
for (const v of array) {
184+
if (v) {
185+
if (isArray(v)) {
186+
addRange(result, v);
187+
}
188+
else {
189+
result.push(v);
190+
}
191+
}
192+
}
193+
}
194+
195+
return result;
196+
}
197+
174198
/**
175199
* Maps an array. If the mapped value is an array, it is spread into the result.
200+
*
201+
* @param array The array to map.
202+
* @param mapfn The callback used to map the result into one or more values.
176203
*/
177-
export function flatMap<T, U>(array: T[], f: (x: T, i: number) => U | U[]): U[] {
204+
export function flatMap<T, U>(array: T[], mapfn: (x: T, i: number) => U | U[]): U[] {
178205
let result: U[];
179206
if (array) {
180207
result = [];
181208
for (let i = 0; i < array.length; i++) {
182-
const v = array[i];
183-
const ar = f(v, i);
184-
if (ar) {
185-
// We cast to <U> here to leverage the behavior of Array#concat
186-
// which will append a single value here.
187-
result = result.concat(<U[]>ar);
209+
const v = mapfn(array[i], i);
210+
if (v) {
211+
if (isArray(v)) {
212+
addRange(result, v);
213+
}
214+
else {
215+
result.push(v);
216+
}
217+
}
218+
}
219+
}
220+
return result;
221+
}
222+
223+
/**
224+
* Maps contiguous spans of values with the same key.
225+
*
226+
* @param array The array to map.
227+
* @param keyfn A callback used to select the key for an element.
228+
* @param mapfn A callback used to map a contiguous chunk of values to a single value.
229+
*/
230+
export function spanMap<T, K, U>(array: T[], keyfn: (x: T, i: number) => K, mapfn: (chunk: T[], key: K) => U): U[] {
231+
let result: U[];
232+
if (array) {
233+
result = [];
234+
const len = array.length;
235+
let previousKey: K;
236+
let key: K;
237+
let start = 0;
238+
let pos = 0;
239+
while (start < len) {
240+
while (pos < len) {
241+
const value = array[pos];
242+
key = keyfn(value, pos);
243+
if (pos === 0) {
244+
previousKey = key;
245+
}
246+
else if (key !== previousKey) {
247+
break;
248+
}
249+
250+
pos++;
188251
}
252+
253+
if (start < pos) {
254+
const v = mapfn(array.slice(start, pos), previousKey);
255+
if (v) {
256+
result.push(v);
257+
}
258+
259+
start = pos;
260+
}
261+
262+
previousKey = key;
263+
pos++;
189264
}
190265
}
266+
191267
return result;
192268
}
193269

src/compiler/emitter.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
346346
};
347347

348348
function isUniqueLocalName(name: string, container: Node): boolean {
349-
for (let node = container; isNodeDescendentOf(node, container); node = node.nextContainer) {
349+
for (let node = container; isNodeDescendantOf(node, container); node = node.nextContainer) {
350350
if (node.locals && hasProperty(node.locals, name)) {
351351
// We conservatively include alias symbols to cover cases where they're emitted as locals
352352
if (node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias)) {
@@ -1529,7 +1529,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15291529
return;
15301530
}
15311531
}
1532-
else if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.BodyScopedClassBinding) {
1532+
else if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.SelfReferenceInDecoratedClass) {
15331533
// Due to the emit for class decorators, any reference to the class from inside of the class body
15341534
// must instead be rewritten to point to a temporary variable to avoid issues with the double-bind
15351535
// behavior of class names in ES6.
@@ -1915,9 +1915,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19151915

19161916
if (multiLine) {
19171917
decreaseIndent();
1918-
if (!compilerOptions.transformCompatibleEmit) {
1919-
writeLine();
1920-
}
19211918
}
19221919

19231920
write(")");
@@ -2237,7 +2234,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22372234
return forEach(elements, e => e.kind === SyntaxKind.SpreadElementExpression);
22382235
}
22392236

2240-
function skipParentheses(node: Expression): Expression {
2237+
function skipParenthesesAndAssertions(node: Expression): Expression {
22412238
while (node.kind === SyntaxKind.ParenthesizedExpression || node.kind === SyntaxKind.TypeAssertionExpression || node.kind === SyntaxKind.AsExpression) {
22422239
node = (<ParenthesizedExpression | AssertionExpression>node).expression;
22432240
}
@@ -2268,7 +2265,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22682265

22692266
function emitCallWithSpread(node: CallExpression) {
22702267
let target: Expression;
2271-
const expr = skipParentheses(node.expression);
2268+
const expr = skipParenthesesAndAssertions(node.expression);
22722269
if (expr.kind === SyntaxKind.PropertyAccessExpression) {
22732270
// Target will be emitted as "this" argument
22742271
target = emitCallTarget((<PropertyAccessExpression>expr).expression);
@@ -4334,9 +4331,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43344331
writeLine();
43354332
emitStart(restParam);
43364333
emitNodeWithCommentsAndWithoutSourcemap(restParam.name);
4337-
write(restIndex > 0 || !compilerOptions.transformCompatibleEmit
4338-
? `[${tempName} - ${restIndex}] = arguments[${tempName}];`
4339-
: `[${tempName}] = arguments[${tempName}];`);
4334+
write(`[${tempName} - ${restIndex}] = arguments[${tempName}];`);
43404335
emitEnd(restParam);
43414336
decreaseIndent();
43424337
writeLine();
@@ -5208,7 +5203,7 @@ const _super = (function (geti, seti) {
52085203
// [Example 4]
52095204
//
52105205

5211-
if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithBodyScopedClassBinding) {
5206+
if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.DecoratedClassWithSelfReference) {
52125207
decoratedClassAlias = unescapeIdentifier(makeUniqueName(node.name ? node.name.text : "default"));
52135208
decoratedClassAliases[getNodeId(node)] = decoratedClassAlias;
52145209
write(`let ${decoratedClassAlias};`);
@@ -5356,7 +5351,7 @@ const _super = (function (geti, seti) {
53565351
const isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === SyntaxKind.ClassExpression;
53575352
let tempVariable: Identifier;
53585353

5359-
if (isClassExpressionWithStaticProperties && compilerOptions.transformCompatibleEmit) {
5354+
if (isClassExpressionWithStaticProperties) {
53605355
tempVariable = createAndRecordTempVariable(TempFlags.Auto);
53615356
write("(");
53625357
increaseIndent();
@@ -5393,11 +5388,6 @@ const _super = (function (geti, seti) {
53935388
writeLine();
53945389
emitConstructor(node, baseTypeNode);
53955390
emitMemberFunctionsForES5AndLower(node);
5396-
if (!compilerOptions.transformCompatibleEmit) {
5397-
emitPropertyDeclarations(node, staticProperties);
5398-
writeLine();
5399-
emitDecoratorsOfClass(node, /*decoratedClassAlias*/ undefined);
5400-
}
54015391
writeLine();
54025392
emitToken(SyntaxKind.CloseBraceToken, node.members.end, () => {
54035393
write("return ");
@@ -5424,13 +5414,10 @@ const _super = (function (geti, seti) {
54245414
write("))");
54255415
if (node.kind === SyntaxKind.ClassDeclaration) {
54265416
write(";");
5427-
if (compilerOptions.transformCompatibleEmit) {
5428-
emitPropertyDeclarations(node, staticProperties);
5429-
writeLine();
5430-
emitDecoratorsOfClass(node, /*decoratedClassAlias*/ undefined);
5431-
}
5417+
emitPropertyDeclarations(node, staticProperties);
5418+
emitDecoratorsOfClass(node, /*decoratedClassAlias*/ undefined);
54325419
}
5433-
else if (isClassExpressionWithStaticProperties && compilerOptions.transformCompatibleEmit) {
5420+
else if (isClassExpressionWithStaticProperties) {
54345421
for (const property of staticProperties) {
54355422
write(",");
54365423
writeLine();

src/compiler/factory.ts

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,21 @@ namespace ts {
153153
* Creates a shallow, memberwise clone of a node for mutation.
154154
*/
155155
export function getMutableNode<T extends Node>(node: T): T {
156-
return cloneNode<T>(node, node, node.flags, node.parent, node);
156+
return cloneNode(node, /*location*/ node, node.flags, /*parent*/ undefined, /*original*/ node);
157+
}
158+
159+
/**
160+
* Creates a shallow, memberwise clone of a node with no source map location.
161+
*/
162+
export function getSynthesizedClone<T extends Node>(node: T): T {
163+
return nodeIsSynthesized(node) ? node : cloneNode(node, /*location*/ undefined, node.flags, /*parent*/ undefined, /*original*/ node);
164+
}
165+
166+
/**
167+
* Creates a shallow, memberwise clone of a node at the specified source map location.
168+
*/
169+
export function getRelocatedClone<T extends Node>(node: T, location: TextRange): T {
170+
return cloneNode(node, location, node.flags, /*parent*/ undefined, /*original*/ node);
157171
}
158172

159173
export function createNodeArrayNode<T extends Node>(elements: T[]): NodeArrayNode<T> {
@@ -185,24 +199,38 @@ namespace ts {
185199

186200
// Identifiers
187201

188-
export function createIdentifier(text: string): Identifier {
189-
const node = <Identifier>createNode(SyntaxKind.Identifier);
202+
export function createIdentifier(text: string, location?: TextRange): Identifier {
203+
const node = <Identifier>createNode(SyntaxKind.Identifier, location);
190204
node.text = text;
191205
return node;
192206
}
193207

194-
export function createTempVariable(): Identifier {
195-
const name = <Identifier>createNode(SyntaxKind.Identifier);
196-
name.text = undefined;
197-
name.tempKind = TempVariableKind.Auto;
208+
export function createTempVariable(location?: TextRange): Identifier {
209+
const name = <Identifier>createNode(SyntaxKind.Identifier, location);
210+
name.autoGenerateKind = GeneratedIdentifierKind.Auto;
211+
getNodeId(name);
212+
return name;
213+
}
214+
215+
export function createLoopVariable(location?: TextRange): Identifier {
216+
const name = <Identifier>createNode(SyntaxKind.Identifier, location);
217+
name.autoGenerateKind = GeneratedIdentifierKind.Loop;
218+
getNodeId(name);
219+
return name;
220+
}
221+
222+
export function createUniqueName(text: string, location?: TextRange): Identifier {
223+
const name = <Identifier>createNode(SyntaxKind.Identifier, location);
224+
name.text = text;
225+
name.autoGenerateKind = GeneratedIdentifierKind.Unique;
198226
getNodeId(name);
199227
return name;
200228
}
201229

202-
export function createLoopVariable(): Identifier {
203-
const name = <Identifier>createNode(SyntaxKind.Identifier);
204-
name.text = undefined;
205-
name.tempKind = TempVariableKind.Loop;
230+
export function getGeneratedNameForNode(node: Node, location?: TextRange): Identifier {
231+
const name = <Identifier>createNode(SyntaxKind.Identifier, location);
232+
name.autoGenerateKind = GeneratedIdentifierKind.Node;
233+
name.original = node;
206234
getNodeId(name);
207235
return name;
208236
}
@@ -1326,8 +1354,4 @@ namespace ts {
13261354
node.flags = flags;
13271355
return node;
13281356
}
1329-
1330-
export function getSynthesizedNode<T extends Node>(node: T): T {
1331-
return nodeIsSynthesized(node) ? node : cloneNode(node, /*location*/ undefined, node.flags, /*parent*/ undefined, /*original*/ node);
1332-
}
13331357
}

0 commit comments

Comments
 (0)
0