Skip to content

Commit cae274d

Browse files
committed
Merge branch 'master' into unionPropertyAccess
2 parents b94679c + 6203675 commit cae274d

238 files changed

Lines changed: 15072 additions & 12301 deletions

File tree

Some content is hidden

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

src/compiler/checker.ts

Lines changed: 149 additions & 108 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: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,11 @@ var __param = this.__param || function(index, decorator) { return function (targ
24692469
writeLine();
24702470
emitStart(node);
24712471
if (node.flags & NodeFlags.Default) {
2472-
write("exports.default");
2472+
if (languageVersion === ScriptTarget.ES3) {
2473+
write("exports[\"default\"]");
2474+
} else {
2475+
write("exports.default");
2476+
}
24732477
}
24742478
else {
24752479
emitModuleMemberName(node);
@@ -4560,7 +4564,11 @@ var __param = this.__param || function(index, decorator) { return function (targ
45604564
writeLine();
45614565
emitStart(node);
45624566
emitContainingModuleName(node);
4563-
write(".default = ");
4567+
if (languageVersion === ScriptTarget.ES3) {
4568+
write("[\"default\"] = ");
4569+
} else {
4570+
write(".default = ");
4571+
}
45644572
emit(node.expression);
45654573
write(";");
45664574
emitEnd(node);
@@ -4621,19 +4629,6 @@ var __param = this.__param || function(index, decorator) { return function (targ
46214629
}
46224630
}
46234631

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-
46374632
function emitExportStarHelper() {
46384633
if (hasExportStars) {
46394634
writeLine();
@@ -4649,44 +4644,83 @@ var __param = this.__param || function(index, decorator) { return function (targ
46494644

46504645
function emitAMDModule(node: SourceFile, startIndex: number) {
46514646
collectExternalModuleInfo(node);
4652-
writeLine();
4653-
write("define(");
4654-
sortAMDModules(node.amdDependencies);
4655-
if (node.amdModuleName) {
4656-
write("\"" + node.amdModuleName + "\", ");
4647+
4648+
// An AMD define function has the following shape:
4649+
// define(id?, dependencies?, factory);
4650+
//
4651+
// This has the shape of
4652+
// define(name, ["module1", "module2"], function (module1Alias) {
4653+
// The location of the alias in the parameter list in the factory function needs to
4654+
// match the position of the module name in the dependency list.
4655+
//
4656+
// To ensure this is true in cases of modules with no aliases, e.g.:
4657+
// `import "module"` or `<amd-dependency path= "a.css" />`
4658+
// we need to add modules without alias names to the end of the dependencies list
4659+
4660+
let aliasedModuleNames: string[] = []; // names of modules with corresponding parameter in the
4661+
// factory function.
4662+
let unaliasedModuleNames: string[] = []; // names of modules with no corresponding parameters in
4663+
// factory function.
4664+
let importAliasNames: string[] = []; // names of the parameters in the factory function; these
4665+
// paramters need to match the indexes of the corresponding
4666+
// module names in aliasedModuleNames.
4667+
4668+
// Fill in amd-dependency tags
4669+
for (let amdDependency of node.amdDependencies) {
4670+
if (amdDependency.name) {
4671+
aliasedModuleNames.push("\"" + amdDependency.path + "\"");
4672+
importAliasNames.push(amdDependency.name);
4673+
}
4674+
else {
4675+
unaliasedModuleNames.push("\"" + amdDependency.path + "\"");
4676+
}
46574677
}
4658-
write("[\"require\", \"exports\"");
4678+
46594679
for (let importNode of externalImports) {
4660-
write(", ");
4680+
// Find the name of the external module
4681+
let externalModuleName = "";
46614682
let moduleName = getExternalModuleName(importNode);
46624683
if (moduleName.kind === SyntaxKind.StringLiteral) {
4663-
emitLiteral(<LiteralExpression>moduleName);
4684+
externalModuleName = getLiteralText(<LiteralExpression>moduleName);
4685+
}
4686+
4687+
// Find the name of the module alais, if there is one
4688+
let importAliasName: string;
4689+
let namespaceDeclaration = getNamespaceDeclarationNode(importNode);
4690+
if (namespaceDeclaration && !isDefaultImport(importNode)) {
4691+
importAliasName = getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name);
46644692
}
46654693
else {
4666-
write("\"\"");
4694+
importAliasName = getGeneratedNameForNode(<ImportDeclaration | ExportDeclaration>importNode);
4695+
}
4696+
4697+
if (importAliasName) {
4698+
aliasedModuleNames.push(externalModuleName);
4699+
importAliasNames.push(importAliasName);
4700+
}
4701+
else {
4702+
unaliasedModuleNames.push(externalModuleName);
46674703
}
46684704
}
4669-
for (let amdDependency of node.amdDependencies) {
4670-
let text = "\"" + amdDependency.path + "\"";
4705+
4706+
writeLine();
4707+
write("define(");
4708+
if (node.amdModuleName) {
4709+
write("\"" + node.amdModuleName + "\", ");
4710+
}
4711+
write("[\"require\", \"exports\"");
4712+
if (aliasedModuleNames.length) {
46714713
write(", ");
4672-
write(text);
4714+
write(aliasedModuleNames.join(", "));
46734715
}
4674-
write("], function (require, exports");
4675-
for (let importNode of externalImports) {
4716+
if (unaliasedModuleNames.length) {
46764717
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-
}
4718+
write(unaliasedModuleNames.join(", "));
46844719
}
4685-
for (let amdDependency of node.amdDependencies) {
4686-
if (amdDependency.name) {
4687-
write(", ");
4688-
write(amdDependency.name);
4689-
}
4720+
write("], function (require, exports");
4721+
if (importAliasNames.length) {
4722+
write(", ");
4723+
write(importAliasNames.join(", "));
46904724
}
46914725
write(") {");
46924726
increaseIndent();

src/compiler/parser.ts

Lines changed: 7 additions & 6 deletions
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

@@ -3859,13 +3859,14 @@ module ts {
38593859
function parseObjectBindingElement(): BindingElement {
38603860
let node = <BindingElement>createNode(SyntaxKind.BindingElement);
38613861
// TODO(andersh): Handle computed properties
3862-
let id = parsePropertyName();
3863-
if (id.kind === SyntaxKind.Identifier && token !== SyntaxKind.ColonToken) {
3864-
node.name = <Identifier>id;
3862+
let tokenIsIdentifier = isIdentifier();
3863+
let propertyName = parsePropertyName();
3864+
if (tokenIsIdentifier && token !== SyntaxKind.ColonToken) {
3865+
node.name = <Identifier>propertyName;
38653866
}
38663867
else {
38673868
parseExpected(SyntaxKind.ColonToken);
3868-
node.propertyName = <Identifier>id;
3869+
node.propertyName = <Identifier>propertyName;
38693870
node.name = parseIdentifierOrPattern();
38703871
}
38713872
node.initializer = parseInitializer(/*inParameter*/ false);
@@ -5416,4 +5417,4 @@ module ts {
54165417
Value = -1
54175418
}
54185419
}
5419-
}
5420+
}

0 commit comments

Comments
 (0)