Skip to content

Commit

Permalink
Merge branch 'release-1.5'
Browse files Browse the repository at this point in the history
Conflicts:
	src/compiler/emitter.ts
	src/compiler/parser.ts
	src/compiler/program.ts
	src/services/services.ts
	tests/cases/unittests/transpile.ts
  • Loading branch information
JsonFreeman committed Jun 18, 2015
2 parents 3cb44fb + fce1423 commit 111fdcb
Show file tree
Hide file tree
Showing 40 changed files with 468 additions and 19 deletions.
4 changes: 2 additions & 2 deletions bin/tsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24740,7 +24740,7 @@ var ts;
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
write(");");
}
emitExportMemberAssignments(node.name);
}
Expand Down Expand Up @@ -24848,7 +24848,7 @@ var ts;
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
write(");");
}
emitExportMemberAssignments(node.name);
}
Expand Down
4 changes: 2 additions & 2 deletions bin/tsserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -25131,7 +25131,7 @@ var ts;
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
write(");");
}
emitExportMemberAssignments(node.name);
}
Expand Down Expand Up @@ -25239,7 +25239,7 @@ var ts;
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
write(");");
}
emitExportMemberAssignments(node.name);
}
Expand Down
4 changes: 2 additions & 2 deletions bin/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -29466,7 +29466,7 @@ var ts;
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
write(");");
}
emitExportMemberAssignments(node.name);
}
Expand Down Expand Up @@ -29576,7 +29576,7 @@ var ts;
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
write(");");
}
emitExportMemberAssignments(node.name);
}
Expand Down
4 changes: 2 additions & 2 deletions bin/typescriptServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -29466,7 +29466,7 @@ var ts;
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
write(");");
}
emitExportMemberAssignments(node.name);
}
Expand Down Expand Up @@ -29576,7 +29576,7 @@ var ts;
emitDeclarationName(node);
write("\", ");
emitDeclarationName(node);
write(")");
write(");");
}
emitExportMemberAssignments(node.name);
}
Expand Down
33 changes: 25 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,21 +365,38 @@ namespace ts {
case SyntaxKind.SourceFile:
if (!isExternalModule(<SourceFile>location)) break;
case SyntaxKind.ModuleDeclaration:
if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.ModuleMember)) {
if (result.flags & meaning || !(result.flags & SymbolFlags.Alias && getDeclarationOfAliasSymbol(result).kind === SyntaxKind.ExportSpecifier)) {
break loop;
}
result = undefined;
}
else if (location.kind === SyntaxKind.SourceFile ||
let moduleExports = getSymbolOfNode(location).exports;
if (location.kind === SyntaxKind.SourceFile ||
(location.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>location).name.kind === SyntaxKind.StringLiteral)) {
result = getSymbolOfNode(location).exports["default"];

// It's an external module. Because of module/namespace merging, a module's exports are in scope,
// yet we never want to treat an export specifier as putting a member in scope. Therefore,
// if the name we find is purely an export specifier, it is not actually considered in scope.
// Two things to note about this:
// 1. We have to check this without calling getSymbol. The problem with calling getSymbol
// on an export specifier is that it might find the export specifier itself, and try to
// resolve it as an alias. This will cause the checker to consider the export specifier
// a circular alias reference when it might not be.
// 2. We check === SymbolFlags.Alias in order to check that the symbol is *purely*
// an alias. If we used &, we'd be throwing out symbols that have non alias aspects,
// which is not the desired behavior.
if (hasProperty(moduleExports, name) &&
moduleExports[name].flags === SymbolFlags.Alias &&
getDeclarationOfKind(moduleExports[name], SyntaxKind.ExportSpecifier)) {
break;
}

result = moduleExports["default"];
let localSymbol = getLocalSymbolForExportDefault(result);
if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) {
break loop;
}
result = undefined;
}

if (result = getSymbol(moduleExports, name, meaning & SymbolFlags.ModuleMember)) {
break loop;
}
break;
case SyntaxKind.EnumDeclaration:
if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.EnumMember)) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5347,7 +5347,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
decreaseIndent();
writeLine();
write("}"); // return
emitTempDeclarations(/*newLine*/ true)
emitTempDeclarations(/*newLine*/ true);
}

function emitSetters(exportStarFunction: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3988,7 +3988,7 @@ namespace ts {
parseExportAssignment(fullStart, decorators, modifiers) :
parseExportDeclaration(fullStart, decorators, modifiers);
default:
if (decorators) {
if (decorators || modifiers) {
// We reached this point because we encountered decorators and/or modifiers and assumed a declaration
// would follow. For recovery and error reporting purposes, return an incomplete declaration.
let node = <Statement>createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
Expand Down Expand Up @@ -4390,7 +4390,7 @@ namespace ts {
return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers);
}

if (decorators) {
if (decorators || modifiers) {
// treat this as a property declaration with a missing name.
let name = <Identifier>createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
return parsePropertyDeclaration(fullStart, decorators, modifiers, name, /*questionToken*/ undefined);
Expand Down
5 changes: 5 additions & 0 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,11 @@ namespace ts {
sourceFile.moduleName = moduleName;
}

// Store syntactic diagnostics
if (diagnostics && sourceFile.parseDiagnostics) {
diagnostics.push(...sourceFile.parseDiagnostics);
}

let newLine = getNewLineCharacter(options);

// Output
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests/cases/compiler/classMemberWithMissingIdentifier.ts(2,11): error TS1146: Declaration expected.
tests/cases/compiler/classMemberWithMissingIdentifier.ts(2,12): error TS1005: '=' expected.


==== tests/cases/compiler/classMemberWithMissingIdentifier.ts (2 errors) ====
class C {
public {};

!!! error TS1146: Declaration expected.
~
!!! error TS1005: '=' expected.
}
12 changes: 12 additions & 0 deletions tests/baselines/reference/classMemberWithMissingIdentifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//// [classMemberWithMissingIdentifier.ts]
class C {
public {};
}

//// [classMemberWithMissingIdentifier.js]
var C = (function () {
function C() {
this. = {};
}
return C;
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,11): error TS1146: Declaration expected.
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,12): error TS1005: '=' expected.
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,14): error TS2304: Cannot find name 'name'.
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,18): error TS1005: ']' expected.
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,19): error TS2304: Cannot find name 'string'.
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,25): error TS1005: ',' expected.
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,26): error TS1136: Property assignment expected.
tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,27): error TS2304: Cannot find name 'VariableDeclaration'.


==== tests/cases/compiler/classMemberWithMissingIdentifier2.ts (8 errors) ====
class C {
public {[name:string]:VariableDeclaration};

!!! error TS1146: Declaration expected.
~
!!! error TS1005: '=' expected.
~~~~
!!! error TS2304: Cannot find name 'name'.
~
!!! error TS1005: ']' expected.
~~~~~~
!!! error TS2304: Cannot find name 'string'.
~
!!! error TS1005: ',' expected.
~
!!! error TS1136: Property assignment expected.
~~~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'VariableDeclaration'.
}
13 changes: 13 additions & 0 deletions tests/baselines/reference/classMemberWithMissingIdentifier2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [classMemberWithMissingIdentifier2.ts]
class C {
public {[name:string]:VariableDeclaration};
}

//// [classMemberWithMissingIdentifier2.js]
var C = (function () {
function C() {
this. = (_a = {}, _a[name] = string, _a.VariableDeclaration = VariableDeclaration, _a);
var _a;
}
return C;
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [exportSpecifierAndExportedMemberDeclaration.ts]
declare module "m2" {
export module X {
interface I { }
}
function Y();
export { Y as X };
function Z(): X.I;
}

declare module "m2" {
function Z2(): X.I;
}

//// [exportSpecifierAndExportedMemberDeclaration.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
=== tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts ===
declare module "m2" {
export module X {
>X : Symbol(X, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 0, 21), Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 12))

interface I { }
>I : Symbol(I, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 1, 21))
}
function Y();
>Y : Symbol(Y, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 3, 5))

export { Y as X };
>Y : Symbol(X, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 0, 21), Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 12))
>X : Symbol(X, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 0, 21), Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 12))

function Z(): X.I;
>Z : Symbol(Z, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 22))
>X : Symbol(X, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 0, 21), Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 12))
>I : Symbol(X.I, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 1, 21))
}

declare module "m2" {
function Z2(): X.I;
>Z2 : Symbol(Z2, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 9, 21))
>X : Symbol(X, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 0, 21), Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 12))
>I : Symbol(X.I, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 1, 21))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
=== tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts ===
declare module "m2" {
export module X {
>X : () => any

interface I { }
>I : I
}
function Y();
>Y : () => any

export { Y as X };
>Y : () => any
>X : () => any

function Z(): X.I;
>Z : () => X.I
>X : any
>I : X.I
}

declare module "m2" {
function Z2(): X.I;
>Z2 : () => X.I
>X : any
>I : X.I
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tests/cases/compiler/exportSpecifierAndLocalMemberDeclaration.ts(11,20): error TS2503: Cannot find namespace 'X'.


==== tests/cases/compiler/exportSpecifierAndLocalMemberDeclaration.ts (1 errors) ====
declare module "m2" {
module X {
interface I { }
}
function Y();
export { Y as X };
function Z(): X.I;
}

declare module "m2" {
function Z2(): X.I;
~
!!! error TS2503: Cannot find namespace 'X'.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [exportSpecifierAndLocalMemberDeclaration.ts]
declare module "m2" {
module X {
interface I { }
}
function Y();
export { Y as X };
function Z(): X.I;
}

declare module "m2" {
function Z2(): X.I;
}

//// [exportSpecifierAndLocalMemberDeclaration.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [exportSpecifierReferencingOuterDeclaration1.ts]
declare module X { export interface bar { } }
declare module "m" {
export { X };
export function foo(): X.bar;
}

//// [exportSpecifierReferencingOuterDeclaration1.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts ===
declare module X { export interface bar { } }
>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 0))
>bar : Symbol(bar, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 18))

declare module "m" {
export { X };
>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 2, 12))

export function foo(): X.bar;
>foo : Symbol(foo, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 2, 17))
>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 0))
>bar : Symbol(X.bar, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 18))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts ===
declare module X { export interface bar { } }
>X : any
>bar : bar

declare module "m" {
export { X };
>X : any

export function foo(): X.bar;
>foo : () => X.bar
>X : any
>bar : X.bar
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2.ts] ////

//// [exportSpecifierReferencingOuterDeclaration2_A.ts]
declare module X { export interface bar { } }

//// [exportSpecifierReferencingOuterDeclaration2_B.ts]
export { X };
export declare function foo(): X.bar;

//// [exportSpecifierReferencingOuterDeclaration2_A.js]
//// [exportSpecifierReferencingOuterDeclaration2_B.js]
Loading

0 comments on commit 111fdcb

Please sign in to comment.