Skip to content

Commit ad314b0

Browse files
committed
Merge branch 'transforms-printer' into transforms-transformer-ts
2 parents 61fe61b + 61f3ba6 commit ad314b0

7 files changed

Lines changed: 37 additions & 10 deletions

File tree

Jakefile.js

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

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

305309
var cmd = host + " " + compilerPath + " " + options + " ";
306310
cmd = cmd + sources.join(" ");
@@ -429,6 +433,10 @@ task("setTransforms", function() {
429433
useTransforms = true;
430434
});
431435

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

src/compiler/commandLineParser.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,18 @@ namespace ts {
322322
description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking
323323
},
324324
{
325+
// this option will be removed when this is merged with master and exists solely
326+
// to enable the tree transforming emitter side-by-side with the existing emitter.
325327
name: "experimentalTransforms",
326328
type: "boolean",
327329
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
328337
}
329338
];
330339

src/compiler/emitter.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19191919

19201920
if (multiLine) {
19211921
decreaseIndent();
1922+
if (!compilerOptions.transformCompatibleEmit) {
1923+
writeLine();
1924+
}
19221925
}
19231926

19241927
write(")");
@@ -4335,7 +4338,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43354338
writeLine();
43364339
emitStart(restParam);
43374340
emitNodeWithCommentsAndWithoutSourcemap(restParam.name);
4338-
write(restIndex > 0
4341+
write(restIndex > 0 || !compilerOptions.transformCompatibleEmit
43394342
? `[${tempName} - ${restIndex}] = arguments[${tempName}];`
43404343
: `[${tempName}] = arguments[${tempName}];`);
43414344
emitEnd(restParam);
@@ -5357,7 +5360,7 @@ const _super = (function (geti, seti) {
53575360
const isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === SyntaxKind.ClassExpression;
53585361
let tempVariable: Identifier;
53595362

5360-
if (isClassExpressionWithStaticProperties) {
5363+
if (isClassExpressionWithStaticProperties && compilerOptions.transformCompatibleEmit) {
53615364
tempVariable = createAndRecordTempVariable(TempFlags.Auto);
53625365
write("(");
53635366
increaseIndent();
@@ -5394,6 +5397,11 @@ const _super = (function (geti, seti) {
53945397
writeLine();
53955398
emitConstructor(node, baseTypeNode);
53965399
emitMemberFunctionsForES5AndLower(node);
5400+
if (!compilerOptions.transformCompatibleEmit) {
5401+
emitPropertyDeclarations(node, staticProperties);
5402+
writeLine();
5403+
emitDecoratorsOfClass(node, /*decoratedClassAlias*/ undefined);
5404+
}
53975405
writeLine();
53985406
emitToken(SyntaxKind.CloseBraceToken, node.members.end, () => {
53995407
write("return ");
@@ -5420,11 +5428,13 @@ const _super = (function (geti, seti) {
54205428
write("))");
54215429
if (node.kind === SyntaxKind.ClassDeclaration) {
54225430
write(";");
5423-
emitPropertyDeclarations(node, staticProperties);
5424-
writeLine();
5425-
emitDecoratorsOfClass(node, /*decoratedClassAlias*/ undefined);
5431+
if (compilerOptions.transformCompatibleEmit) {
5432+
emitPropertyDeclarations(node, staticProperties);
5433+
writeLine();
5434+
emitDecoratorsOfClass(node, /*decoratedClassAlias*/ undefined);
5435+
}
54265436
}
5427-
else if (isClassExpressionWithStaticProperties) {
5437+
else if (isClassExpressionWithStaticProperties && compilerOptions.transformCompatibleEmit) {
54285438
for (const property of staticProperties) {
54295439
write(",");
54305440
writeLine();

src/compiler/program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// <reference path="sys.ts" />
22
/// <reference path="emitter.ts" />
33
/// <reference path="core.ts" />
4+
/// <reference path="printer.ts" />
45

56
namespace ts {
67
/* @internal */ export let programTime = 0;

src/compiler/transformer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ namespace ts {
7575
}
7676

7777
currentSourceFile = sourceFile;
78-
const visited = transformation(sourceFile);
79-
currentSourceFile = undefined;
80-
return visited;
78+
return transformation(sourceFile);
8179
}
8280

8381
function enableExpressionSubstitution(kind: SyntaxKind) {

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,7 @@ namespace ts {
24702470
allowJs?: boolean;
24712471
/* @internal */ stripInternal?: boolean;
24722472
/* @internal */ experimentalTransforms?: boolean;
2473+
/* @internal */ transformCompatibleEmit?: boolean;
24732474

24742475
// Skip checking lib.d.ts to help speed up tests.
24752476
/* @internal */ skipDefaultLibCheck?: boolean;

src/services/formatting/smartIndenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ namespace ts.formatting {
204204
// - parent is SourceFile - by default immediate children of SourceFile are not indented except when user indents them manually
205205
// - parent and child are not on the same line
206206
let useActualIndentation =
207-
(isDeclaration(current) || isStatement(current)) &&
207+
(isDeclaration(current) || isStatementButNotDeclaration(current)) &&
208208
(parent.kind === SyntaxKind.SourceFile || !parentAndChildShareLine);
209209

210210
if (!useActualIndentation) {

0 commit comments

Comments
 (0)