mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fixes generated names and some formatting in system modules.
This commit is contained in:
@@ -424,11 +424,11 @@ namespace ts {
|
||||
return block;
|
||||
}
|
||||
|
||||
export function createVariableStatement(modifiers: Modifier[], declarationList: VariableDeclarationList, location?: TextRange): VariableStatement {
|
||||
export function createVariableStatement(modifiers: Modifier[], declarationList: VariableDeclarationList | VariableDeclaration[], location?: TextRange): VariableStatement {
|
||||
const node = <VariableStatement>createNode(SyntaxKind.VariableStatement, location);
|
||||
node.decorators = undefined;
|
||||
node.modifiers = modifiers ? createNodeArray(modifiers) : undefined;
|
||||
node.declarationList = declarationList;
|
||||
node.declarationList = isArray(declarationList) ? createVariableDeclarationList(declarationList) : declarationList;
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
+34
-13
@@ -2343,14 +2343,12 @@ const _super = (function (geti, seti) {
|
||||
return node;
|
||||
}
|
||||
|
||||
function getTextOfNode(node: Node, includeTrivia?: boolean) {
|
||||
if (isIdentifier(node)) {
|
||||
if (node.autoGenerateKind) {
|
||||
return getGeneratedIdentifier(node);
|
||||
}
|
||||
else if (nodeIsSynthesized(node) || !node.parent) {
|
||||
return unescapeIdentifier(node.text);
|
||||
}
|
||||
function getTextOfNode(node: Node, includeTrivia?: boolean): string {
|
||||
if (isGeneratedIdentifier(node)) {
|
||||
return getGeneratedIdentifier(node);
|
||||
}
|
||||
else if (isIdentifier(node) && (nodeIsSynthesized(node) || !node.parent)) {
|
||||
return unescapeIdentifier(node.text);
|
||||
}
|
||||
else if (isLiteralExpression(node) && (nodeIsSynthesized(node) || !node.parent)) {
|
||||
return node.text;
|
||||
@@ -2452,7 +2450,7 @@ const _super = (function (geti, seti) {
|
||||
}
|
||||
|
||||
function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) {
|
||||
const name = node.name.text;
|
||||
const name = getTextOfNode(node.name);
|
||||
// Use module/enum name itself if it is unique, otherwise make a unique variation
|
||||
return isUniqueLocalName(name, node) ? name : makeUniqueName(name);
|
||||
}
|
||||
@@ -2472,10 +2470,10 @@ const _super = (function (geti, seti) {
|
||||
return makeUniqueName("class");
|
||||
}
|
||||
|
||||
function generateNameForNode(node: Node) {
|
||||
function generateNameForNode(node: Node): string {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
return makeUniqueName((<Identifier>node).text);
|
||||
return makeUniqueName(getTextOfNode(node));
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
return generateNameForModuleOrEnum(<ModuleDeclaration | EnumDeclaration>node);
|
||||
@@ -2502,14 +2500,37 @@ const _super = (function (geti, seti) {
|
||||
case GeneratedIdentifierKind.Unique:
|
||||
return makeUniqueName(node.text);
|
||||
case GeneratedIdentifierKind.Node:
|
||||
return generateNameForNode(getOriginalNode(node));
|
||||
return generateNameForNode(getSourceNodeForGeneratedName(node));
|
||||
}
|
||||
}
|
||||
|
||||
function getGeneratedIdentifier(node: Identifier) {
|
||||
const id = getOriginalNodeId(node);
|
||||
const id = getNodeIdForGeneratedIdentifier(node);
|
||||
return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = unescapeIdentifier(generateIdentifier(node)));
|
||||
}
|
||||
|
||||
function getSourceNodeForGeneratedName(name: Identifier) {
|
||||
let node: Node = name;
|
||||
while (node.original !== undefined) {
|
||||
node = node.original;
|
||||
if (isIdentifier(node) && node.autoGenerateKind === GeneratedIdentifierKind.Node) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
function getNodeIdForGeneratedIdentifier(node: Identifier) {
|
||||
switch (node.autoGenerateKind) {
|
||||
case GeneratedIdentifierKind.Auto:
|
||||
case GeneratedIdentifierKind.Loop:
|
||||
case GeneratedIdentifierKind.Unique:
|
||||
return getNodeId(node);
|
||||
case GeneratedIdentifierKind.Node:
|
||||
return getNodeId(getSourceNodeForGeneratedName(node));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createDelimiterMap() {
|
||||
|
||||
@@ -365,20 +365,18 @@ namespace ts {
|
||||
ensureIdentifier(propertyName.expression, /*reuseIdentifierExpressions*/ false, /*location*/ propertyName, emitTempVariableAssignment)
|
||||
);
|
||||
}
|
||||
else if (isIdentifier(propertyName)) {
|
||||
return createPropertyAccess(
|
||||
expression,
|
||||
propertyName.text
|
||||
);
|
||||
}
|
||||
else {
|
||||
// We create a synthetic copy of the identifier in order to avoid the rewriting that might
|
||||
// otherwise occur when the identifier is emitted.
|
||||
else if (isLiteralExpression(propertyName)) {
|
||||
return createElementAccess(
|
||||
expression,
|
||||
getSynthesizedClone(propertyName)
|
||||
);
|
||||
}
|
||||
else {
|
||||
return createPropertyAccess(
|
||||
expression,
|
||||
isGeneratedIdentifier(propertyName) ? getSynthesizedClone(propertyName) : createIdentifier(propertyName.text)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -339,7 +339,8 @@ 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 = createUniqueName(forEach(group.externalImports, getLocalNameTextForExternalImport) || "");
|
||||
const localName = forEach(group.externalImports, getLocalNameForExternalImport);
|
||||
const parameterName = localName ? getGeneratedNameForNode(localName) : createUniqueName("");
|
||||
const statements: Statement[] = [];
|
||||
for (const entry of group.externalImports) {
|
||||
const importVariableName = getLocalNameForExternalImport(entry);
|
||||
@@ -1121,11 +1122,6 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getLocalNameTextForExternalImport(node: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration): string {
|
||||
const name = getLocalNameForExternalImport(node);
|
||||
return name ? name.text : undefined;
|
||||
}
|
||||
|
||||
function getLocalNameForExternalImport(node: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration): Identifier {
|
||||
const namespaceDeclaration = getNamespaceDeclarationNode(node);
|
||||
if (namespaceDeclaration && !isDefaultImport(node)) {
|
||||
@@ -1182,14 +1178,17 @@ namespace ts {
|
||||
]),
|
||||
m,
|
||||
createBlock([
|
||||
createIf(
|
||||
condition,
|
||||
createStatement(
|
||||
createAssignment(
|
||||
createElementAccess(exports, n),
|
||||
createElementAccess(m, n)
|
||||
setNodeEmitFlags(
|
||||
createIf(
|
||||
condition,
|
||||
createStatement(
|
||||
createAssignment(
|
||||
createElementAccess(exports, n),
|
||||
createElementAccess(m, n)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
NodeEmitFlags.SingleLine
|
||||
)
|
||||
])
|
||||
),
|
||||
|
||||
@@ -480,6 +480,7 @@ namespace ts {
|
||||
// @kind(SyntaxKind.StaticKeyword)
|
||||
export interface Modifier extends Node { }
|
||||
|
||||
/*@internal*/
|
||||
export const enum GeneratedIdentifierKind {
|
||||
None, // Not automatically generated.
|
||||
Auto, // Automatically generated identifier.
|
||||
@@ -490,9 +491,9 @@ namespace ts {
|
||||
|
||||
// @kind(SyntaxKind.Identifier)
|
||||
export interface Identifier extends PrimaryExpression {
|
||||
text: string; // Text of identifier (with escapes converted to characters)
|
||||
originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later
|
||||
autoGenerateKind?: GeneratedIdentifierKind; // Specifies whether to auto-generate the text for an identifier.
|
||||
text: string; // Text of identifier (with escapes converted to characters)
|
||||
originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later
|
||||
/*@internal*/ autoGenerateKind?: GeneratedIdentifierKind; // Specifies whether to auto-generate the text for an identifier.
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.QualifiedName)
|
||||
|
||||
@@ -22,8 +22,8 @@ System.register(["foo"], function (exports_1, context_1) {
|
||||
var foo_1, cls, cls2, x, y, z, M;
|
||||
return {
|
||||
setters: [
|
||||
function (_1) {
|
||||
foo_1 = _1;
|
||||
function (foo_1_1) {
|
||||
foo_1 = foo_1_1;
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
|
||||
@@ -10,13 +10,13 @@ export class Foo {
|
||||
}
|
||||
|
||||
//// [b.js]
|
||||
System.register([], function(exports_1, context_1) {
|
||||
System.register([], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var Foo;
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
Foo = (function () {
|
||||
function Foo() {
|
||||
}
|
||||
@@ -24,21 +24,21 @@ System.register([], function(exports_1, context_1) {
|
||||
}());
|
||||
exports_1("Foo", Foo);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
//// [a.js]
|
||||
System.register(["./b"], function(exports_1, context_1) {
|
||||
System.register(["./b"], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var b_1;
|
||||
var x;
|
||||
var b_1, x;
|
||||
return {
|
||||
setters:[
|
||||
setters: [
|
||||
function (b_1_1) {
|
||||
b_1 = b_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
exports_1("x", x = new b_1["default"].Foo());
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -11,13 +11,13 @@ export class Foo {
|
||||
|
||||
|
||||
//// [b.js]
|
||||
System.register([], function(exports_1, context_1) {
|
||||
System.register([], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var Foo;
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
Foo = (function () {
|
||||
function Foo() {
|
||||
}
|
||||
@@ -25,21 +25,21 @@ System.register([], function(exports_1, context_1) {
|
||||
}());
|
||||
exports_1("Foo", Foo);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
//// [a.js]
|
||||
System.register(["./b"], function(exports_1, context_1) {
|
||||
System.register(["./b"], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var b_1;
|
||||
var x;
|
||||
var b_1, x;
|
||||
return {
|
||||
setters:[
|
||||
setters: [
|
||||
function (b_1_1) {
|
||||
b_1 = b_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
exports_1("x", x = new b_1["default"].Foo());
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -12,18 +12,18 @@ export var x = new Foo();
|
||||
|
||||
|
||||
//// [a.js]
|
||||
System.register(["./b"], function(exports_1, context_1) {
|
||||
System.register(["./b"], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var b_1;
|
||||
var x;
|
||||
var b_1, x;
|
||||
return {
|
||||
setters:[
|
||||
setters: [
|
||||
function (b_1_1) {
|
||||
b_1 = b_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
exports_1("x", x = new b_1["default"]());
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -12,18 +12,18 @@ export var x = new Foo();
|
||||
|
||||
|
||||
//// [a.js]
|
||||
System.register(["./b"], function(exports_1, context_1) {
|
||||
System.register(["./b"], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var b_1;
|
||||
var x;
|
||||
var b_1, x;
|
||||
return {
|
||||
setters:[
|
||||
setters: [
|
||||
function (b_1_1) {
|
||||
b_1 = b_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
exports_1("x", x = new b_1["default"]());
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -29,6 +29,6 @@ var n: number;
|
||||
//// [consumer.js]
|
||||
"use strict";
|
||||
// Ambient external module members are always exported with or without export keyword when module lacks export assignment
|
||||
var imp3 = require('equ2');
|
||||
var imp3 = require("equ2");
|
||||
var n = imp3.x;
|
||||
var n;
|
||||
|
||||
@@ -3,5 +3,4 @@ export declare module "M" { }
|
||||
|
||||
//// [ambientExternalModuleInsideNonAmbientExternalModule.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ var c = new A();
|
||||
|
||||
//// [ambientExternalModuleWithInternalImportDeclaration_0.js]
|
||||
//// [ambientExternalModuleWithInternalImportDeclaration_1.js]
|
||||
define(["require", "exports", 'M'], function (require, exports, A) {
|
||||
define(["require", "exports", "M"], function (require, exports, A) {
|
||||
"use strict";
|
||||
var c = new A();
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ var c = new A();
|
||||
|
||||
//// [ambientExternalModuleWithoutInternalImportDeclaration_0.js]
|
||||
//// [ambientExternalModuleWithoutInternalImportDeclaration_1.js]
|
||||
define(["require", "exports", 'M'], function (require, exports, A) {
|
||||
define(["require", "exports", "M"], function (require, exports, A) {
|
||||
"use strict";
|
||||
var c = new A();
|
||||
});
|
||||
|
||||
@@ -7,5 +7,4 @@ export declare module M { }
|
||||
|
||||
//// [ambientInsideNonAmbientExternalModule.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
});
|
||||
|
||||
@@ -16,8 +16,8 @@ System.register(["file1", "file2"], function (exports_1, context_1) {
|
||||
var file1_1, n2;
|
||||
return {
|
||||
setters: [
|
||||
function (_1) {
|
||||
file1_1 = _1;
|
||||
function (file1_1_1) {
|
||||
file1_1 = file1_1_1;
|
||||
},
|
||||
function (n2_1) {
|
||||
n2 = n2_1;
|
||||
|
||||
@@ -16,8 +16,8 @@ System.register(["file1", "file2"], function (exports_1, context_1) {
|
||||
var file1_1, n2;
|
||||
return {
|
||||
setters: [
|
||||
function (_1) {
|
||||
file1_1 = _1;
|
||||
function (file1_1_1) {
|
||||
file1_1 = file1_1_1;
|
||||
},
|
||||
function (n2_1) {
|
||||
n2 = n2_1;
|
||||
|
||||
@@ -20,8 +20,8 @@ System.register(["foo"], function (exports_1, context_1) {
|
||||
var foo_1, x;
|
||||
return {
|
||||
setters: [
|
||||
function (_1) {
|
||||
foo_1 = _1;
|
||||
function (foo_1_1) {
|
||||
foo_1 = foo_1_1;
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
|
||||
@@ -43,22 +43,22 @@ System.register(["file1", "file2", "file3", "file4", "file5", "file6", "file7"],
|
||||
function (ns_1) {
|
||||
ns = ns_1;
|
||||
},
|
||||
function (file2_1_1) {
|
||||
file2_1 = file2_1_1;
|
||||
},
|
||||
function (file3_1_1) {
|
||||
file3_1 = file3_1_1;
|
||||
},
|
||||
function (_1) {
|
||||
file2_1 = _1;
|
||||
},
|
||||
function (_2) {
|
||||
file3_1 = _2;
|
||||
},
|
||||
function (_3) {
|
||||
},
|
||||
function (_4) {
|
||||
file5_1 = _4;
|
||||
function (file5_1_1) {
|
||||
file5_1 = file5_1_1;
|
||||
},
|
||||
function (ns3_1) {
|
||||
ns3 = ns3_1;
|
||||
},
|
||||
function (_5) {
|
||||
exportStar_1(_5);
|
||||
function (file7_1_1) {
|
||||
exportStar_1(file7_1_1);
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
|
||||
Reference in New Issue
Block a user