Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
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
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
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
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
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
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
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
16 changes: 1 addition & 15 deletions src/compiler/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ namespace ts {
addPropertyAssignment(properties, "enumerable", enumerable, preferNewLine);
addPropertyAssignment(properties, "configurable", configurable, preferNewLine);
addPropertyAssignment(properties, "writable", writable, preferNewLine);
return createObjectLiteral(properties, location)
return createObjectLiteral(properties, location);
}

function addPropertyAssignment(properties: ObjectLiteralElement[], name: string, value: boolean | Expression, preferNewLine: boolean) {
Expand Down Expand Up @@ -1303,20 +1303,6 @@ namespace ts {
return node;
}

/**
* Skips past any TypeAssertionExpression or AsExpression nodes to their inner expression.
*
* @param node The expression node.
*/
function skipAssertions(node: Expression) {
while (node.kind === SyntaxKind.TypeAssertionExpression
|| node.kind === SyntaxKind.AsExpression) {
node = (<AssertionExpression>node).expression;
}

return node;
}

export function startOnNewLine<T extends Node>(node: T): T {
node.startsOnNewLine = true;
return node;
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ const _super = (function (geti, seti) {
const comments = createCommentWriter(host, writer, sourceMap);
const {
getLeadingComments,
getLeadingCommentsOfPosition,
getTrailingComments,
getTrailingCommentsOfPosition,
emitLeadingComments,
Expand Down Expand Up @@ -2421,7 +2420,7 @@ const _super = (function (geti, seti) {
function createBracketsMap() {
const brackets: string[][] = [];
brackets[ListFormat.Braces] = ["{", "}"];
brackets[ListFormat.Parenthesis] = ["(",")"];
brackets[ListFormat.Parenthesis] = ["(", ")"];
brackets[ListFormat.AngleBrackets] = ["<", ">"];
brackets[ListFormat.SquareBrackets] = ["[", "]"];
return brackets;
Expand Down
64 changes: 26 additions & 38 deletions src/compiler/transformers/es6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ namespace ts {
addExtendsHelperIfNeeded(statements, node, hasExtendsClause);
addConstructor(statements, node, hasExtendsClause);
addClassMembers(statements, node);
addLine(statements, createReturn(getDeclarationName(node)));
addLines(statements, endLexicalEnvironment());
return createBlock(statements);
addNode(statements, createReturn(getDeclarationName(node)));
addNodes(statements, endLexicalEnvironment());
return setMultiLine(createBlock(statements), /*multiLine*/ true);
}

function addExtendsHelperIfNeeded(classStatements: Statement[], node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean): void {
if (hasExtendsClause) {
addLine(classStatements,
addNode(classStatements,
createStatement(
createExtendsHelper(getDeclarationName(node))
)
Expand All @@ -256,7 +256,7 @@ namespace ts {
function addConstructor(classStatements: Statement[], node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean): void {
const constructor = getFirstConstructorWithBody(node);
const hasSynthesizedSuper = hasSynthesizedDefaultSuperCall(constructor, hasExtendsClause);
addLine(classStatements,
addNode(classStatements,
createFunctionDeclaration(
/*modifiers*/ undefined,
/*asteriskToken*/ undefined,
Expand Down Expand Up @@ -291,13 +291,13 @@ namespace ts {
addNodes(statements, visitNodes(constructor.body.statements, visitor, isStatement, hasSynthesizedSuper ? 1 : 0));
}

addLines(statements, endLexicalEnvironment());
return createBlock(statements, /*location*/ constructor && constructor.body);
addNodes(statements, endLexicalEnvironment());
return setMultiLine(createBlock(statements, /*location*/ constructor && constructor.body), /*multiLine*/ true);
}

function addDefaultSuperCall(statements: Statement[], constructor: ConstructorDeclaration, hasExtendsClause: boolean, hasSynthesizedSuper: boolean) {
if (constructor ? hasSynthesizedSuper : hasExtendsClause) {
addLine(statements,
addNode(statements,
createStatement(
createFunctionApply(
createIdentifier("_super"),
Expand Down Expand Up @@ -370,7 +370,7 @@ namespace ts {
// we usually don't want to emit a var declaration; however, in the presence
// of an initializer, we must emit that expression to preserve side effects.
if (name.elements.length > 0) {
addLine(statements,
addNode(statements,
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList(
Expand All @@ -380,7 +380,7 @@ namespace ts {
);
}
else if (initializer) {
addLine(statements,
addNode(statements,
createStatement(
createAssignment(
temp,
Expand All @@ -396,7 +396,7 @@ namespace ts {
}

function addDefaultValueAssignmentForInitializer(statements: Statement[], parameter: ParameterDeclaration, name: Identifier, initializer: Expression): void {
addLine(statements,
addNode(statements,
createIf(
createStrictEquality(
getSynthesizedNode(name),
Expand Down Expand Up @@ -436,7 +436,7 @@ namespace ts {
const temp = createLoopVariable();

// var param = [];
addLine(statements,
addNode(statements,
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList([
Expand All @@ -451,7 +451,7 @@ namespace ts {
// for (var _i = restIndex; _i < arguments.length; _i++) {
// param[_i - restIndex] = arguments[_i];
// }
addLine(statements,
addNode(statements,
createFor(
createVariableDeclarationList([
createVariableDeclaration(temp, createLiteral(restIndex))
Expand Down Expand Up @@ -482,7 +482,7 @@ namespace ts {
if (node.transformFlags & TransformFlags.ContainsCapturedLexicalThis && node.kind !== SyntaxKind.ArrowFunction) {
enableExpressionSubstitutionForCapturedThis();

addLine(statements,
addNode(statements,
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList([
Expand All @@ -500,19 +500,19 @@ namespace ts {
for (const member of node.members) {
switch (member.kind) {
case SyntaxKind.SemicolonClassElement:
addLine(classStatements, transformSemicolonClassElementToStatement(<SemicolonClassElement>member));
addNode(classStatements, transformSemicolonClassElementToStatement(<SemicolonClassElement>member));
break;

case SyntaxKind.MethodDeclaration:
addLine(classStatements, transformClassMethodDeclarationToStatement(node, <MethodDeclaration>member));
addNode(classStatements, transformClassMethodDeclarationToStatement(node, <MethodDeclaration>member));
break;

case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
const accessors = getAllAccessorDeclarations(node.members, <AccessorDeclaration>member);
if (member === accessors.firstAccessor) {
const receiver = getClassMemberPrefix(node, member);
addLine(classStatements, transformAccessorsToStatement(receiver, accessors));
addNode(classStatements, transformAccessorsToStatement(receiver, accessors));
}

break;
Expand Down Expand Up @@ -639,7 +639,7 @@ namespace ts {
}
}

addLines(statements, endLexicalEnvironment());
addNodes(statements, endLexicalEnvironment());
return createBlock(statements, node.body);
}

Expand Down Expand Up @@ -804,9 +804,7 @@ namespace ts {
// for-of bodies are always emitted as blocks.

const expression = visitNode(node.expression, visitor, isExpression);
const rhsIsIdentifier = expression.kind === SyntaxKind.Identifier;
const initializer = node.initializer;
const loopDeclarations: VariableDeclaration[] = [];
const loopBodyStatements: Statement[] = [];

// In the case where the user wrote an identifier as the RHS, like this:
Expand All @@ -822,12 +820,11 @@ namespace ts {
// Initialize LHS
// var v = _a[_i];
if (isVariableDeclarationList(initializer)) {
const declarations: VariableDeclaration[] = [];
const firstDeclaration = firstOrUndefined(initializer.declarations);
if (firstDeclaration && isBindingPattern(firstDeclaration.name)) {
// This works whether the declaration is a var, let, or const.
// It will use rhsIterationValue _a[_i] as the initializer.
addLine(loopBodyStatements,
addNode(loopBodyStatements,
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList(
Expand All @@ -844,7 +841,7 @@ namespace ts {
else {
// The following call does not include the initializer, so we have
// to emit it separately.
addLine(loopBodyStatements,
addNode(loopBodyStatements,
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList([
Expand All @@ -864,7 +861,7 @@ namespace ts {
const assignment = createAssignment(initializer, createElementAccess(rhsReference, counter));
if (isDestructuringAssignment(assignment)) {
// This is a destructuring pattern, so we flatten the destructuring instead.
addLine(loopBodyStatements,
addNode(loopBodyStatements,
createStatement(
flattenDestructuringAssignment(
assignment,
Expand All @@ -876,7 +873,7 @@ namespace ts {
);
}
else {
addLine(loopBodyStatements, createStatement(assignment, /*location*/ node.initializer));
addNode(loopBodyStatements, createStatement(assignment, /*location*/ node.initializer));
}
}

Expand Down Expand Up @@ -909,10 +906,6 @@ namespace ts {
);
}

function shouldConvertLoopBody(node: IterationStatement): boolean {
return (resolver.getNodeCheckFlags(node) & NodeCheckFlags.LoopWithCapturedBlockScopedBinding) !== 0;
}

function visitObjectLiteralExpression(node: ObjectLiteralExpression): LeftHandSideExpression {
// We are here because a ComputedPropertyName was used somewhere in the expression.
const properties = node.properties;
Expand All @@ -936,8 +929,6 @@ namespace ts {
hoistVariableDeclaration(temp);

// Write out the first non-computed properties, then emit the rest through indexing on the temp variable.
let initialProperties = visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialNonComputedProperties);

const expressions: Expression[] = [];
addNode(expressions,
createAssignment(
Expand Down Expand Up @@ -1067,7 +1058,7 @@ namespace ts {
target,
thisArg,
transformAndSpreadElements(node.arguments, /*needsUniqueCopy*/ false, /*multiLine*/ false)
)
);
}
else {
Debug.assert(isSuperCall(node));
Expand Down Expand Up @@ -1285,7 +1276,7 @@ namespace ts {
// thus we need to remove those characters.
// First template piece starts with "`", others with "}"
// Last template piece ends with "`", others with "${"
let isLast = node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail;
const isLast = node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail;
text = text.substring(1, text.length - (isLast ? 1 : 2));

// Newline normalization:
Expand Down Expand Up @@ -1363,7 +1354,6 @@ namespace ts {
}

function visitSuperKeyword(node: PrimaryExpression): LeftHandSideExpression {
const expression = createIdentifier("_super");
return containingNonArrowFunction
&& isClassElement(containingNonArrowFunction)
&& (containingNonArrowFunction.flags & NodeFlags.Static) === 0
Expand All @@ -1375,7 +1365,7 @@ namespace ts {
const clone = cloneNode(node, node, node.flags, /*parent*/ undefined, node);
const statements: Statement[] = [];
startLexicalEnvironment();
let statementOffset = addPrologueDirectives(statements, node.statements);
const statementOffset = addPrologueDirectives(statements, node.statements);
addCaptureThisForNodeIfNeeded(statements, node);
addNodes(statements, visitNodes(node.statements, visitor, isStatement, statementOffset));
addNodes(statements, endLexicalEnvironment());
Expand All @@ -1384,7 +1374,7 @@ namespace ts {
}

function addPrologueDirectives(to: Statement[], from: NodeArray<Statement>): number {
for (let i = 0; i < from.length; ++i) {
for (let i = 0; i < from.length; i++) {
if (isPrologueDirective(from[i])) {
addNode(to, from[i]);
}
Expand All @@ -1396,8 +1386,6 @@ namespace ts {
return from.length;
}

var inEmit: boolean;

function onBeforeEmitNode(node: Node) {
previousOnBeforeEmitNode(node);

Expand Down
2 changes: 2 additions & 0 deletions src/compiler/transformers/es7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/*@internal*/
namespace ts {
export function transformES7(context: TransformationContext) {
const { hoistVariableDeclaration } = context;

return transformSourceFile;

function transformSourceFile(node: SourceFile) {
Expand Down
Loading