Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Merge branch 'transforms-transformer-es6' into transforms-transformer…
…-module
  • Loading branch information
rbuckton committed Mar 2, 2016
commit 70cbb9b3309148a76333352aa454826a84e300f3
7 changes: 6 additions & 1 deletion src/compiler/transformers/es6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ namespace ts {
const [prologue, remaining] = span(node.statements, isPrologueDirective);
const statements: Statement[] = [];
startLexicalEnvironment();
const statementOffset = copyPrologueDirectives(node.statements, statements);
addRange(statements, prologue);
addCaptureThisForNodeIfNeeded(statements, node);
addRange(statements, visitNodes(createNodeArray(remaining), visitor, isStatement));
addRange(statements, endLexicalEnvironment());
Expand All @@ -1710,6 +1710,11 @@ namespace ts {
return clone;
}

/**
* Called by the printer just before a node is printed.
*
* @param node The node to be printed.
*/
function onBeforeEmitNode(node: Node) {
previousOnBeforeEmitNode(node);

Expand Down
19 changes: 9 additions & 10 deletions src/compiler/transformers/module/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace ts {
};

const {
getGeneratedNameForNode,
startLexicalEnvironment,
endLexicalEnvironment,
hoistVariableDeclaration,
Expand Down Expand Up @@ -229,7 +228,7 @@ namespace ts {
// import * as n from "mod";
addNode(variables,
createVariableDeclaration(
getSynthesizedNode(namespaceDeclaration.name),
getSynthesizedClone(namespaceDeclaration.name),
createRequireCall(node)
)
);
Expand All @@ -249,7 +248,7 @@ namespace ts {
if (namespaceDeclaration && isDefaultImport(node)) {
addNode(variables,
createVariableDeclaration(
getSynthesizedNode(namespaceDeclaration.name),
getSynthesizedClone(namespaceDeclaration.name),
getGeneratedNameForNode(node)
)
);
Expand All @@ -272,7 +271,7 @@ namespace ts {
/*modifiers*/ undefined,
createVariableDeclarationList([
createVariableDeclaration(
getSynthesizedNode(namespaceDeclaration.name),
getSynthesizedClone(namespaceDeclaration.name),
getGeneratedNameForNode(node),
/*location*/ node
)
Expand Down Expand Up @@ -309,7 +308,7 @@ namespace ts {
/*modifiers*/ undefined,
createVariableDeclarationList([
createVariableDeclaration(
getSynthesizedNode(node.name),
getSynthesizedClone(node.name),
createRequireCall(node),
/*location*/ node
)
Expand Down Expand Up @@ -519,7 +518,7 @@ namespace ts {
);

if (node.flags & NodeFlags.Default) {
addExportDefault(statements, getSynthesizedNode(node.name), /*location*/ node);
addExportDefault(statements, getSynthesizedClone(node.name), /*location*/ node);
}
}
else {
Expand Down Expand Up @@ -559,7 +558,7 @@ namespace ts {
);

if (node.flags & NodeFlags.Default) {
addExportDefault(statements, getSynthesizedNode(node.name), /*location*/ node);
addExportDefault(statements, getSynthesizedClone(node.name), /*location*/ node);
}
}
else {
Expand Down Expand Up @@ -598,7 +597,7 @@ namespace ts {
if (container && container.kind === SyntaxKind.SourceFile) {
return createPropertyAccess(
createIdentifier("exports"),
getSynthesizedNode(node),
getSynthesizedClone(node),
/*location*/ node
);
}
Expand Down Expand Up @@ -638,7 +637,7 @@ namespace ts {
const moduleName = getExternalModuleName(importNode);
if (moduleName.kind === SyntaxKind.StringLiteral) {
return tryRenameExternalModule(<StringLiteral>moduleName)
|| getSynthesizedNode(<StringLiteral>moduleName);
|| getSynthesizedClone(<StringLiteral>moduleName);
}

return undefined;
Expand Down Expand Up @@ -685,7 +684,7 @@ namespace ts {
)
: createPropertyAccess(
createIdentifier("exports"),
getSynthesizedNode(name)
getSynthesizedClone(name)
),
value
);
Expand Down
40 changes: 19 additions & 21 deletions src/compiler/transformers/module/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace ts {
}

const {
getGeneratedNameForNode,
makeUniqueName,
startLexicalEnvironment,
endLexicalEnvironment,
hoistVariableDeclaration,
Expand Down Expand Up @@ -83,8 +81,8 @@ namespace ts {

// Make sure that the name of the 'exports' function does not conflict with
// existing identifiers.
exportFunctionForFile = makeUniqueName("exports");
contextObjectForFile = makeUniqueName("context");
exportFunctionForFile = createUniqueName("exports");
contextObjectForFile = createUniqueName("context");

const dependencyGroups = collectDependencyGroups(externalImports);

Expand Down Expand Up @@ -299,7 +297,7 @@ namespace ts {
}
}

const exportedNamesStorageRef = makeUniqueName("exportedNames");
const exportedNamesStorageRef = createUniqueName("exportedNames");
addNode(statements,
createVariableStatement(
/*modifiers*/ undefined,
Expand All @@ -323,7 +321,7 @@ namespace ts {
const setters: Expression[] = [];
for (const group of dependencyGroups) {
// derive a unique name for parameter from the first named entry in the group
const parameterName = makeUniqueName(forEach(group.externalImports, getLocalNameTextForExternalImport) || "");
const parameterName = createUniqueName(forEach(group.externalImports, getLocalNameTextForExternalImport) || "");
const statements: Statement[] = [];
for (const entry of group.externalImports) {
const importVariableName = getLocalNameForExternalImport(entry);
Expand Down Expand Up @@ -705,7 +703,7 @@ namespace ts {
function visitForInStatement(node: ForInStatement): ForInStatement {
const initializer = node.initializer;
if (isVariableDeclarationList(initializer)) {
const updated = getMutableNode(node);
const updated = getMutableClone(node);
updated.initializer = transformForBinding(initializer);
updated.statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
return updated;
Expand All @@ -723,7 +721,7 @@ namespace ts {
function visitForOfStatement(node: ForOfStatement): ForOfStatement {
const initializer = node.initializer;
if (isVariableDeclarationList(initializer)) {
const updated = getMutableNode(node);
const updated = getMutableClone(node);
updated.initializer = transformForBinding(initializer);
updated.statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
return updated;
Expand All @@ -741,7 +739,7 @@ namespace ts {
function visitDoStatement(node: DoStatement) {
const statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
if (statement !== node.statement) {
const updated = getMutableNode(node);
const updated = getMutableClone(node);
updated.statement = statement;
return updated;
}
Expand All @@ -756,7 +754,7 @@ namespace ts {
function visitWhileStatement(node: WhileStatement) {
const statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
if (statement !== node.statement) {
const updated = getMutableNode(node);
const updated = getMutableClone(node);
updated.statement = statement;
return updated;
}
Expand All @@ -771,7 +769,7 @@ namespace ts {
function visitLabeledStatement(node: LabeledStatement) {
const statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
if (statement !== node.statement) {
const updated = getMutableNode(node);
const updated = getMutableClone(node);
updated.statement = statement;
return updated;
}
Expand All @@ -786,7 +784,7 @@ namespace ts {
function visitWithStatement(node: WithStatement) {
const statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
if (statement !== node.statement) {
const updated = getMutableNode(node);
const updated = getMutableClone(node);
updated.statement = statement;
return updated;
}
Expand All @@ -801,7 +799,7 @@ namespace ts {
function visitSwitchStatement(node: SwitchStatement) {
const caseBlock = visitNode(node.caseBlock, visitNestedNode, isCaseBlock);
if (caseBlock !== node.caseBlock) {
const updated = getMutableNode(node);
const updated = getMutableClone(node);
updated.caseBlock = caseBlock;
return updated;
}
Expand All @@ -816,7 +814,7 @@ namespace ts {
function visitCaseBlock(node: CaseBlock) {
const clauses = visitNodes(node.clauses, visitNestedNode, isCaseOrDefaultClause);
if (clauses !== node.clauses) {
const updated = getMutableNode(node);
const updated = getMutableClone(node);
updated.clauses = clauses;
return updated;
}
Expand All @@ -831,7 +829,7 @@ namespace ts {
function visitCaseClause(node: CaseClause) {
const statements = visitNodes(node.statements, visitNestedNode, isStatement);
if (statements !== node.statements) {
const updated = getMutableNode(node);
const updated = getMutableClone(node);
updated.statements = statements;
return updated;
}
Expand Down Expand Up @@ -864,7 +862,7 @@ namespace ts {
function visitCatchClause(node: CatchClause) {
const block = visitNode(node.block, visitNestedNode, isBlock);
if (block !== node.block) {
const updated = getMutableNode(node);
const updated = getMutableClone(node);
updated.block = block;
return updated;
}
Expand Down Expand Up @@ -1055,7 +1053,7 @@ namespace ts {
const moduleName = getExternalModuleName(importNode);
if (moduleName.kind === SyntaxKind.StringLiteral) {
return tryRenameExternalModule(<StringLiteral>moduleName)
|| getSynthesizedNode(<StringLiteral>moduleName);
|| getSynthesizedClone(<StringLiteral>moduleName);
}

return undefined;
Expand Down Expand Up @@ -1096,11 +1094,11 @@ namespace ts {
* @param node The declaration statement.
*/
function getDeclarationName(node: DeclarationStatement) {
return node.name ? getSynthesizedNode(node.name) : getGeneratedNameForNode(node);
return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node);
}

function addExportStarFunction(statements: Statement[], localNames: Identifier) {
const exportStarFunction = makeUniqueName("exportStar");
const exportStarFunction = createUniqueName("exportStar");
const m = createIdentifier("m");
const n = createIdentifier("n");
const exports = createIdentifier("exports");
Expand Down Expand Up @@ -1204,7 +1202,7 @@ namespace ts {
return createElementAccess(importAlias, createLiteral(name.text));
}
else {
return createPropertyAccess(importAlias, getSynthesizedNode(name));
return createPropertyAccess(importAlias, getSynthesizedClone(name));
}
}

Expand Down Expand Up @@ -1256,7 +1254,7 @@ namespace ts {
function hoistBindingElement(node: VariableDeclaration | BindingElement, isExported: boolean) {
const name = node.name;
if (isIdentifier(name)) {
hoistVariableDeclaration(getSynthesizedNode(name));
hoistVariableDeclaration(getSynthesizedClone(name));
if (isExported) {
recordExportName(name);
}
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.