Skip to content

Commit 8ca7805

Browse files
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript into lazyBaseTypes
2 parents 2c4404b + 5426526 commit 8ca7805

File tree

167 files changed

+14145
-12185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+14145
-12185
lines changed

src/compiler/checker.ts

Lines changed: 42 additions & 37 deletions
Large diffs are not rendered by default.

src/compiler/declarationEmitter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ module ts {
258258
handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
259259
}
260260

261-
function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode | StringLiteralExpression, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
261+
function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
262262
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
263263
write(": ");
264264
if (type) {
@@ -314,12 +314,12 @@ module ts {
314314
}
315315
}
316316

317-
function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type: TypeNode | EntityName | HeritageClauseElement, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
317+
function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type: TypeNode | EntityName, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
318318
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
319319
emitType(type);
320320
}
321321

322-
function emitType(type: TypeNode | StringLiteralExpression | Identifier | QualifiedName | HeritageClauseElement) {
322+
function emitType(type: TypeNode | Identifier | QualifiedName) {
323323
switch (type.kind) {
324324
case SyntaxKind.AnyKeyword:
325325
case SyntaxKind.StringKeyword:
@@ -1126,7 +1126,7 @@ module ts {
11261126
writeLine();
11271127
}
11281128

1129-
function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | StringLiteralExpression {
1129+
function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode {
11301130
if (accessor) {
11311131
return accessor.kind === SyntaxKind.GetAccessor
11321132
? accessor.type // Getter - return type

src/compiler/emitter.ts

Lines changed: 65 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4621,19 +4621,6 @@ var __param = this.__param || function(index, decorator) { return function (targ
46214621
}
46224622
}
46234623

4624-
function sortAMDModules(amdModules: {name: string; path: string}[]) {
4625-
// AMD modules with declared variable names go first
4626-
return amdModules.sort((moduleA, moduleB) => {
4627-
if (moduleA.name === moduleB.name) {
4628-
return 0;
4629-
} else if (!moduleA.name) {
4630-
return 1;
4631-
} else {
4632-
return -1;
4633-
}
4634-
});
4635-
}
4636-
46374624
function emitExportStarHelper() {
46384625
if (hasExportStars) {
46394626
writeLine();
@@ -4649,44 +4636,83 @@ var __param = this.__param || function(index, decorator) { return function (targ
46494636

46504637
function emitAMDModule(node: SourceFile, startIndex: number) {
46514638
collectExternalModuleInfo(node);
4652-
writeLine();
4653-
write("define(");
4654-
sortAMDModules(node.amdDependencies);
4655-
if (node.amdModuleName) {
4656-
write("\"" + node.amdModuleName + "\", ");
4639+
4640+
// An AMD define function has the following shape:
4641+
// define(id?, dependencies?, factory);
4642+
//
4643+
// This has the shape of
4644+
// define(name, ["module1", "module2"], function (module1Alias) {
4645+
// The location of the alias in the parameter list in the factory function needs to
4646+
// match the position of the module name in the dependency list.
4647+
//
4648+
// To ensure this is true in cases of modules with no aliases, e.g.:
4649+
// `import "module"` or `<amd-dependency path= "a.css" />`
4650+
// we need to add modules without alias names to the end of the dependencies list
4651+
4652+
let aliasedModuleNames: string[] = []; // names of modules with corresponding parameter in the
4653+
// factory function.
4654+
let unaliasedModuleNames: string[] = []; // names of modules with no corresponding parameters in
4655+
// factory function.
4656+
let importAliasNames: string[] = []; // names of the parameters in the factory function; these
4657+
// paramters need to match the indexes of the corresponding
4658+
// module names in aliasedModuleNames.
4659+
4660+
// Fill in amd-dependency tags
4661+
for (let amdDependency of node.amdDependencies) {
4662+
if (amdDependency.name) {
4663+
aliasedModuleNames.push("\"" + amdDependency.path + "\"");
4664+
importAliasNames.push(amdDependency.name);
4665+
}
4666+
else {
4667+
unaliasedModuleNames.push("\"" + amdDependency.path + "\"");
4668+
}
46574669
}
4658-
write("[\"require\", \"exports\"");
4670+
46594671
for (let importNode of externalImports) {
4660-
write(", ");
4672+
// Find the name of the external module
4673+
let externalModuleName = "";
46614674
let moduleName = getExternalModuleName(importNode);
46624675
if (moduleName.kind === SyntaxKind.StringLiteral) {
4663-
emitLiteral(<LiteralExpression>moduleName);
4676+
externalModuleName = getLiteralText(<LiteralExpression>moduleName);
4677+
}
4678+
4679+
// Find the name of the module alais, if there is one
4680+
let importAliasName: string;
4681+
let namespaceDeclaration = getNamespaceDeclarationNode(importNode);
4682+
if (namespaceDeclaration && !isDefaultImport(importNode)) {
4683+
importAliasName = getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name);
4684+
}
4685+
else {
4686+
importAliasName = getGeneratedNameForNode(<ImportDeclaration | ExportDeclaration>importNode);
4687+
}
4688+
4689+
if (importAliasName) {
4690+
aliasedModuleNames.push(externalModuleName);
4691+
importAliasNames.push(importAliasName);
46644692
}
46654693
else {
4666-
write("\"\"");
4694+
unaliasedModuleNames.push(externalModuleName);
46674695
}
46684696
}
4669-
for (let amdDependency of node.amdDependencies) {
4670-
let text = "\"" + amdDependency.path + "\"";
4697+
4698+
writeLine();
4699+
write("define(");
4700+
if (node.amdModuleName) {
4701+
write("\"" + node.amdModuleName + "\", ");
4702+
}
4703+
write("[\"require\", \"exports\"");
4704+
if (aliasedModuleNames.length) {
46714705
write(", ");
4672-
write(text);
4706+
write(aliasedModuleNames.join(", "));
46734707
}
4674-
write("], function (require, exports");
4675-
for (let importNode of externalImports) {
4708+
if (unaliasedModuleNames.length) {
46764709
write(", ");
4677-
let namespaceDeclaration = getNamespaceDeclarationNode(importNode);
4678-
if (namespaceDeclaration && !isDefaultImport(importNode)) {
4679-
emit(namespaceDeclaration.name);
4680-
}
4681-
else {
4682-
write(getGeneratedNameForNode(<ImportDeclaration | ExportDeclaration>importNode));
4683-
}
4710+
write(unaliasedModuleNames.join(", "));
46844711
}
4685-
for (let amdDependency of node.amdDependencies) {
4686-
if (amdDependency.name) {
4687-
write(", ");
4688-
write(amdDependency.name);
4689-
}
4712+
write("], function (require, exports");
4713+
if (importAliasNames.length) {
4714+
write(", ");
4715+
write(importAliasNames.join(", "));
46904716
}
46914717
write(") {");
46924718
increaseIndent();

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ module ts {
18031803
function parseParameterType(): TypeNode {
18041804
if (parseOptional(SyntaxKind.ColonToken)) {
18051805
return token === SyntaxKind.StringLiteral
1806-
? <StringLiteralTypeNode>parseLiteralNode(/*internName:*/ true)
1806+
? <StringLiteral>parseLiteralNode(/*internName:*/ true)
18071807
: parseType();
18081808
}
18091809

src/compiler/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,11 @@ module ts {
596596
type: TypeNode;
597597
}
598598

599-
export interface StringLiteralTypeNode extends LiteralExpression, TypeNode { }
599+
// Note that a StringLiteral AST node is both an Expression and a TypeNode. The latter is
600+
// because string literals can appear in the type annotation of a parameter node.
601+
export interface StringLiteral extends LiteralExpression, TypeNode {
602+
_stringLiteralBrand: any;
603+
}
600604

601605
// Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing.
602606
// Consider 'Expression'. Without the brand, 'Expression' is actually no different
@@ -689,10 +693,6 @@ module ts {
689693
hasExtendedUnicodeEscape?: boolean;
690694
}
691695

692-
export interface StringLiteralExpression extends LiteralExpression {
693-
_stringLiteralExpressionBrand: any;
694-
}
695-
696696
export interface TemplateExpression extends PrimaryExpression {
697697
head: LiteralExpression;
698698
templateSpans: NodeArray<TemplateSpan>;
@@ -739,7 +739,7 @@ module ts {
739739
arguments: NodeArray<Expression>;
740740
}
741741

742-
export interface HeritageClauseElement extends Node {
742+
export interface HeritageClauseElement extends TypeNode {
743743
expression: LeftHandSideExpression;
744744
typeArguments?: NodeArray<TypeNode>;
745745
}

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,4 +1913,4 @@ module ts {
19131913

19141914
return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength:*/ newEndN - oldStartN);
19151915
}
1916-
}
1916+
}

0 commit comments

Comments
 (0)