Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
6b381ec
Added printer
rbuckton Feb 9, 2016
e545f1b
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 9, 2016
49d2d93
Adds destructuring logic and placeholders for each transformer.
rbuckton Feb 9, 2016
f948b14
Adds the TypeScript transformer
rbuckton Feb 12, 2016
c634a36
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 13, 2016
8ec3932
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 17, 2016
357171f
PR feedback, switched to getEmitScriptTarget/getEmitModuleKind
rbuckton Feb 17, 2016
c4dc2ae
Merge branch 'transforms-transformer' into transforms-transformer-ts
rbuckton Feb 17, 2016
6c0551f
Adds initial jsx transformer
rbuckton Feb 17, 2016
1ceb02a
Added initial ES7 transformer
rbuckton Feb 17, 2016
dd2dc78
Enables source maps for exceptions thrown in the compiler (when avail…
rbuckton Feb 20, 2016
c759b63
Adds ES6 transformer
rbuckton Feb 20, 2016
39628d7
Added CommonJS/AMD/UMD module transformer
rbuckton Feb 20, 2016
5564537
Added initial SystemJS transformer.
rbuckton Feb 22, 2016
90a317f
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 22, 2016
6d27336
Merged some changes from other branches.
rbuckton Feb 23, 2016
f52a30b
Merged some changes from other branches.
rbuckton Feb 23, 2016
64e7aa8
PR Feedback.
rbuckton Feb 23, 2016
0a325ee
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
3d8cb51
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Feb 23, 2016
0145009
Merge branch 'transforms-transformer-jsx' into transforms-transformer…
rbuckton Feb 23, 2016
dc0b043
Merge branch 'transforms-transformer-es7' into transforms-transformer…
rbuckton Feb 23, 2016
0b64048
Merge branch 'transforms-transformer-es6' into transforms-transformer…
rbuckton Feb 23, 2016
617e511
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
61fe61b
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
c166a2d
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Feb 23, 2016
5b7bd63
Merge branch 'transforms-transformer-jsx' into transforms-transformer…
rbuckton Feb 23, 2016
6d111e3
Merge branch 'transforms-transformer-es7' into transforms-transformer…
rbuckton Feb 23, 2016
2e47e2e
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
e5cd8fe
Added temporary compat flag to control emit output to fix tests
rbuckton Feb 23, 2016
61f3ba6
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
ad314b0
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
98ab964
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
52c62d0
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
f484ff4
Reenabled transforms.
rbuckton Feb 23, 2016
9871d3b
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
de9866f
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
02b85f8
PR feedback
rbuckton Feb 23, 2016
40b61fb
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
75b2181
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
951ce55
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
08036b7
Fixed linter warnings, added comments and minor cleanup.
rbuckton Feb 24, 2016
608822d
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Feb 24, 2016
c9f5253
Fixed linter warnings
rbuckton Feb 24, 2016
25f4102
Reverted change to emitter to force use of printFiles
rbuckton Feb 24, 2016
cde3b34
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Feb 24, 2016
5a9b131
Merge branch 'transforms-transformer-jsx' into transforms-transformer…
rbuckton Feb 24, 2016
78dfab8
Merge branch 'transforms-transformer-es7' into transforms-transformer…
rbuckton Feb 24, 2016
0d8e152
Merge branch 'transforms-transformer-es6' into transforms-transformer…
rbuckton Feb 24, 2016
72bfd2f
Fixed linter warnings.
rbuckton Feb 24, 2016
cd2cf7d
PR Feedback and defer makeUniqueName/getGeneratedNameForNode to printer.
rbuckton Feb 29, 2016
b1d8828
Remove transformCompatibleEmit flag and make it the default.
rbuckton Feb 29, 2016
8e5e5f8
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 29, 2016
359875b
PR Feedback
rbuckton Feb 29, 2016
fe7ad5f
Minor tweaks to naming
rbuckton Feb 29, 2016
a0dbe76
PR Feedback
rbuckton Mar 1, 2016
a7f9cda
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Mar 1, 2016
7d05ba2
Fixed visitJsxText, plus PR Feedback
rbuckton Mar 1, 2016
186f5c8
PR Feedback
rbuckton Mar 1, 2016
2c9cd2e
Merge branch 'transforms-transformer-jsx' into transforms-transformer…
rbuckton Mar 1, 2016
88e1772
Merge branch 'transforms-transformer-es7' into transforms-transformer…
rbuckton Mar 1, 2016
30433c2
ES6 cleanup
rbuckton Mar 2, 2016
2d2709f
Fixed typo in visitCallExpression
rbuckton Mar 2, 2016
70cbb9b
Merge branch 'transforms-transformer-es6' into transforms-transformer…
rbuckton Mar 2, 2016
ebb4764
Switch from onBefore/onAfterEmitNode to onEmitNode
rbuckton Mar 2, 2016
e66e51d
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Mar 2, 2016
8b35af4
Switched to onEmitNode
rbuckton Mar 2, 2016
1fdaf74
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Mar 2, 2016
593fbd4
Merge branch 'transforms-transformer-jsx' into transforms-transformer…
rbuckton Mar 2, 2016
7b28b48
Merge branch 'transforms-transformer-es7' into transforms-transformer…
rbuckton Mar 2, 2016
1c73818
Switched to onEmitNode
rbuckton Mar 2, 2016
c4a75ba
Merge branch 'transforms-transformer-es6' into transforms-transformer…
rbuckton Mar 2, 2016
72eebdb
Switched to onEmitNode
rbuckton Mar 2, 2016
1cf183b
Fixed invalid assertion in ts transformer
rbuckton Mar 4, 2016
d89e21a
General fixes and cleanup
rbuckton Mar 8, 2016
5b8cf96
Moved modifier related flags to separate enum
rbuckton Mar 10, 2016
99e6ad8
Removed ModifiersArray
rbuckton Mar 10, 2016
47cdfbe
Add support for array return values from visitors
rbuckton Mar 10, 2016
2699bf9
Removed NodeArrayNode in favor of arrays
rbuckton Mar 10, 2016
94018a1
cleaned up assertions and removed flattenNodes.
rbuckton Mar 10, 2016
ad0dd4e
Fixed perf issue in binder, plus PR feedback
rbuckton Mar 18, 2016
44ca7d4
Updated baselines
rbuckton Mar 18, 2016
ae7843d
PR Feedback
rbuckton Mar 18, 2016
3c5f170
Merge pull request #7206 from Microsoft/transforms-transformer-module
rbuckton Mar 18, 2016
07a3d18
Merge pull request #7194 from Microsoft/transforms-transformer-es6
rbuckton Mar 18, 2016
cc00f4c
Merge pull request #7193 from Microsoft/transforms-transformer-es7
rbuckton Mar 18, 2016
829a9df
Merge pull request #7192 from Microsoft/transforms-transformer-jsx
rbuckton Mar 18, 2016
ca9148e
Merge pull request #7191 from Microsoft/transforms-transformer-ts
rbuckton Mar 18, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ function concatenateFiles(destinationFile, sourceFiles) {
}

var useDebugMode = true;
var useTransforms = process.env.USE_TRANSFORMS || false;
var host = (process.env.host || process.env.TYPESCRIPT_HOST || "node");
var compilerFilename = "tsc.js";
var LKGCompiler = path.join(LKGDirectory, compilerFilename);
Expand Down Expand Up @@ -297,6 +298,10 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
options += " --stripInternal"
}

if (useBuiltCompiler && useTransforms) {
options += " --experimentalTransforms"
}

var cmd = host + " " + compilerPath + " " + options + " ";
cmd = cmd + sources.join(" ");
console.log(cmd + "\n");
Expand Down Expand Up @@ -420,6 +425,10 @@ task("setDebugMode", function() {
useDebugMode = true;
});

task("setTransforms", function() {
useTransforms = true;
});

task("configure-nightly", [configureNightlyJs], function() {
var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + programTs;
console.log(cmd);
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ namespace ts {
name: "allowSyntheticDefaultImports",
type: "boolean",
description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking
},
{
name: "experimentalTransforms",
type: "boolean",
experimental: true
}
];

Expand Down
138 changes: 86 additions & 52 deletions src/compiler/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ namespace ts {
export interface CommentWriter {
reset(): void;
setSourceFile(sourceFile: SourceFile): void;
getLeadingCommentsToEmit(node: TextRange): CommentRange[];
getTrailingCommentsToEmit(node: TextRange): CommentRange[];
emitDetachedComments(node: TextRange): void;
emitLeadingComments(node: TextRange, comments?: CommentRange[]): void;
emitTrailingComments(node: TextRange, comments?: CommentRange[]): void;
getLeadingComments(range: Node, getAdditionalRange?: (range: Node) => Node): CommentRange[];
getLeadingComments(range: TextRange): CommentRange[];
getLeadingCommentsOfPosition(pos: number): CommentRange[];
getTrailingComments(range: Node, getAdditionalRange?: (range: Node) => Node): CommentRange[];
getTrailingComments(range: TextRange): CommentRange[];
getTrailingCommentsOfPosition(pos: number): CommentRange[];
emitLeadingComments(range: TextRange, comments?: CommentRange[]): void;
emitTrailingComments(range: TextRange, comments?: CommentRange[]): void;
emitDetachedComments(range: TextRange): void;
}

export function createCommentWriter(host: EmitHost, writer: EmitTextWriter, sourceMap: SourceMapWriter): CommentWriter {
Expand All @@ -25,8 +29,8 @@ namespace ts {
// This maps start->end for a comment range. See `hasConsumedCommentRange` and
// `consumeCommentRange` for usage.
let consumedCommentRanges: number[];
let leadingCommentRangeNodeStarts: boolean[];
let trailingCommentRangeNodeEnds: boolean[];
let leadingCommentRangePositions: boolean[];
let trailingCommentRangePositions: boolean[];

return compilerOptions.removeComments
? createCommentRemovingWriter()
Expand All @@ -36,11 +40,13 @@ namespace ts {
return {
reset,
setSourceFile,
getLeadingCommentsToEmit(node: TextRange): CommentRange[] { return undefined; },
getTrailingCommentsToEmit(node: TextRange): CommentRange[] { return undefined; },
getLeadingComments(range: TextRange, getAdditionalRange?: (range: TextRange) => TextRange): CommentRange[] { return undefined; },
getLeadingCommentsOfPosition(pos: number): CommentRange[] { return undefined; },
getTrailingComments(range: TextRange, getAdditionalRange?: (range: TextRange) => TextRange): CommentRange[] { return undefined; },
getTrailingCommentsOfPosition(pos: number): CommentRange[] { return undefined; },
emitLeadingComments(range: TextRange, comments?: CommentRange[]): void { },
emitTrailingComments(range: TextRange, comments?: CommentRange[]): void { },
emitDetachedComments,
emitLeadingComments(node: TextRange, comments?: CommentRange[]): void { },
emitTrailingComments(node: TextRange, comments?: CommentRange[]): void { },
};

function emitDetachedComments(node: TextRange): void {
Expand All @@ -53,41 +59,85 @@ namespace ts {
return {
reset,
setSourceFile,
getLeadingCommentsToEmit,
getTrailingCommentsToEmit,
emitDetachedComments,
getLeadingComments,
getLeadingCommentsOfPosition,
getTrailingComments,
getTrailingCommentsOfPosition,
emitLeadingComments,
emitTrailingComments,
emitDetachedComments,
};

function getLeadingCommentsToEmit(node: TextRange) {
if (nodeIsSynthesized(node)) {
return;
function getLeadingComments(range: TextRange | Node, getAdditionalRange?: (range: Node) => Node) {
let comments = getLeadingCommentsOfPosition(range.pos);
if (getAdditionalRange) {
let additionalRange = getAdditionalRange(<Node>range);
while (additionalRange) {
comments = concatenate(
getLeadingCommentsOfPosition(additionalRange.pos),
comments
);

additionalRange = getAdditionalRange(additionalRange);
}
}

if (!leadingCommentRangeNodeStarts[node.pos]) {
leadingCommentRangeNodeStarts[node.pos] = true;
const comments = hasDetachedComments(node.pos)
? getLeadingCommentsWithoutDetachedComments()
: getLeadingCommentRanges(currentText, node.pos);
return consumeCommentRanges(comments);
return comments;
}

function getTrailingComments(range: TextRange | Node, getAdditionalRange?: (range: Node) => Node) {
let comments = getTrailingCommentsOfPosition(range.end);
if (getAdditionalRange) {
let additionalRange = getAdditionalRange(<Node>range);
while (additionalRange) {
comments = concatenate(
comments,
getTrailingCommentsOfPosition(additionalRange.end)
);

additionalRange = getAdditionalRange(additionalRange);
}
}

return noComments;
return comments;
}

function getTrailingCommentsToEmit(node: TextRange) {
if (nodeIsSynthesized(node)) {
return;
function getLeadingCommentsOfPosition(pos: number) {
if (positionIsSynthesized(pos) || leadingCommentRangePositions[pos]) {
return undefined;
}

if (!trailingCommentRangeNodeEnds[node.end]) {
trailingCommentRangeNodeEnds[node.end] = true;
const comments = getTrailingCommentRanges(currentText, node.end);
return consumeCommentRanges(comments);
leadingCommentRangePositions[pos] = true;
const comments = hasDetachedComments(pos)
? getLeadingCommentsWithoutDetachedComments()
: getLeadingCommentRanges(currentText, pos);
return consumeCommentRanges(comments);
}

function getTrailingCommentsOfPosition(pos: number) {
if (positionIsSynthesized(pos) || trailingCommentRangePositions[pos]) {
return undefined;
}

return noComments;
trailingCommentRangePositions[pos] = true;
const comments = getTrailingCommentRanges(currentText, pos);
return consumeCommentRanges(comments);
}

function emitLeadingComments(range: TextRange, comments = getLeadingComments(range)) {
emitNewLineBeforeLeadingComments(currentLineMap, writer, range, comments);

// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
emitComments(currentText, currentLineMap, writer, comments, /*leadingSeparator*/ false, /*trailingSeparator*/ true, newLine, writeComment);
}

function emitTrailingComments(range: TextRange, comments = getTrailingComments(range)) {
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/
emitComments(currentText, currentLineMap, writer, comments, /*leadingSeparator*/ true, /*trailingSeparator*/ false, newLine, writeComment);
}

function emitDetachedComments(range: TextRange) {
emitDetachedCommentsAndUpdateCommentsInfo(range, /*removeComments*/ false);
}

function hasConsumedCommentRange(comment: CommentRange) {
Expand Down Expand Up @@ -136,22 +186,6 @@ namespace ts {

return noComments;
}

function emitLeadingComments(range: TextRange, leadingComments: CommentRange[] = getLeadingCommentsToEmit(range)) {
emitNewLineBeforeLeadingComments(currentLineMap, writer, range, leadingComments);

// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
emitComments(currentText, currentLineMap, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment);
}

function emitTrailingComments(range: TextRange, trailingComments = getTrailingCommentsToEmit(range)) {
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/
emitComments(currentText, currentLineMap, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment);
}

function emitDetachedComments(range: TextRange) {
emitDetachedCommentsAndUpdateCommentsInfo(range, /*removeComments*/ false);
}
}

function reset() {
Expand All @@ -160,8 +194,8 @@ namespace ts {
currentLineMap = undefined;
detachedCommentsInfo = undefined;
consumedCommentRanges = undefined;
trailingCommentRangeNodeEnds = undefined;
leadingCommentRangeNodeStarts = undefined;
trailingCommentRangePositions = undefined;
leadingCommentRangePositions = undefined;
}

function setSourceFile(sourceFile: SourceFile) {
Expand All @@ -170,8 +204,8 @@ namespace ts {
currentLineMap = getLineStarts(sourceFile);
detachedCommentsInfo = undefined;
consumedCommentRanges = [];
leadingCommentRangeNodeStarts = [];
trailingCommentRangeNodeEnds = [];
leadingCommentRangePositions = [];
trailingCommentRangePositions = [];
}

function hasDetachedComments(pos: number) {
Expand Down
9 changes: 7 additions & 2 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,20 @@ namespace ts {
return result;
}

export function flatMap<T, U>(array: T[], f: (x: T, i: number) => U[]): U[] {
/**
* Maps an array. If the mapped value is an array, it is spread into the result.
*/
export function flatMap<T, U>(array: T[], f: (x: T, i: number) => U | U[]): U[] {
let result: U[];
if (array) {
result = [];
for (let i = 0; i < array.length; i++) {
const v = array[i];
const ar = f(v, i);
if (ar) {
result = result.concat(ar);
// We cast to <U> here to leverage the behavior of Array#concat
// which will append a single value here.
result = result.concat(<U[]>ar);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/declarationEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace ts {
// Emit reference in dts, if the file reference was not already emitted
if (referencedFile && !contains(emittedReferencedFiles, referencedFile)) {
// Add a reference to generated dts file,
// global file reference is added only
// global file reference is added only
// - if it is not bundled emit (because otherwise it would be self reference)
// - and it is not already added
if (writeReferencePath(referencedFile, !isBundledEmit && !addedGlobalFileReference)) {
Expand Down Expand Up @@ -144,7 +144,7 @@ namespace ts {

if (!isBundledEmit && isExternalModule(sourceFile) && sourceFile.moduleAugmentations.length && !resultHasExternalModuleIndicator) {
// if file was external module with augmentations - this fact should be preserved in .d.ts as well.
// in case if we didn't write any external module specifiers in .d.ts we need to emit something
// in case if we didn't write any external module specifiers in .d.ts we need to emit something
// that will force compiler to think that this file is an external module - 'export {}' is a reasonable choice here.
write("export {};");
writeLine();
Expand Down Expand Up @@ -349,7 +349,7 @@ namespace ts {
const jsDocComments = getJsDocCommentsFromText(declaration, currentText);
emitNewLineBeforeLeadingComments(currentLineMap, writer, declaration, jsDocComments);
// jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space
emitComments(currentText, currentLineMap, writer, jsDocComments, /*trailingSeparator*/ true, newLine, writeCommentRange);
emitComments(currentText, currentLineMap, writer, jsDocComments, /*leadingSeparator*/ false, /*trailingSeparator*/ true, newLine, writeCommentRange);
}
}

Expand Down Expand Up @@ -736,7 +736,7 @@ namespace ts {

function emitExternalModuleSpecifier(parent: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration) {
// emitExternalModuleSpecifier is usually called when we emit something in the.d.ts file that will make it an external module (i.e. import/export declarations).
// the only case when it is not true is when we call it to emit correct name for module augmentation - d.ts files with just module augmentations are not considered
// the only case when it is not true is when we call it to emit correct name for module augmentation - d.ts files with just module augmentations are not considered
// external modules since they are indistingushable from script files with ambient modules. To fix this in such d.ts files we'll emit top level 'export {}'
// so compiler will treat them as external modules.
resultHasExternalModuleIndicator = resultHasExternalModuleIndicator || parent.kind !== SyntaxKind.ModuleDeclaration;
Expand Down
Loading