initial version of declaration emit for default export

This commit is contained in:
Vladimir Matveev
2015-03-16 18:54:13 -07:00
parent e9ea336771
commit 218736b23f
34 changed files with 274 additions and 4 deletions
+6
View File
@@ -11157,6 +11157,11 @@ module ts {
getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
}
function writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) {
var type = getTypeOfExpression(expr);
getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
}
function isUnknownIdentifier(location: Node, name: string): boolean {
Debug.assert(!nodeIsSynthesized(location), "isUnknownIdentifier called with a synthesized location");
return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) &&
@@ -11200,6 +11205,7 @@ module ts {
isImplementationOfOverload,
writeTypeOfDeclaration,
writeReturnTypeOfSignatureDeclaration,
writeTypeOfExpression,
isSymbolAccessible,
isEntityNameVisible,
getConstantValue,
@@ -411,6 +411,7 @@ module ts {
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." },
Default_export_of_the_module_has_or_is_using_private_name_0: { code: 4081, category: DiagnosticCategory.Error, key: "Default export of the module has or is using private name '{0}'." },
Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: DiagnosticCategory.Error, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." },
The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." },
+4
View File
@@ -1637,6 +1637,10 @@
"category": "Error",
"code": 4081
},
"Default export of the module has or is using private name '{0}'.": {
"category": "Error",
"code": 4081
},
"Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.": {
"category": "Error",
"code": 4091
+18 -4
View File
@@ -751,7 +751,14 @@ module ts {
function emitExportAssignment(node: ExportAssignment) {
write(node.isExportEquals ? "export = " : "export default ");
writeTextOfNode(currentSourceFile, node.expression);
if (node.expression.kind === SyntaxKind.Identifier) {
writeTextOfNode(currentSourceFile, node.expression);
}
else {
write(": ");
writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic;
resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
}
write(";");
writeLine();
@@ -762,8 +769,12 @@ module ts {
// write each of these declarations asynchronously
writeAsynchronousModuleElements(nodes);
}
else {
Debug.fail("TODO(fixme)")
function getDefaultExportAccessibilityDiagnostic(diagnostic: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
return {
diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0,
errorNode: node
};
}
}
@@ -839,7 +850,10 @@ module ts {
write("export ");
}
if (node.kind !== SyntaxKind.InterfaceDeclaration) {
if (node.flags & NodeFlags.Default) {
write("default ");
}
else if (node.kind !== SyntaxKind.InterfaceDeclaration) {
write("declare ");
}
}
+1
View File
@@ -1214,6 +1214,7 @@ module ts {
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
@@ -949,6 +949,7 @@ declare module "typescript" {
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
@@ -3071,6 +3071,17 @@ declare module "typescript" {
>flags : TypeFormatFlags
>TypeFormatFlags : TypeFormatFlags
>writer : SymbolWriter
>SymbolWriter : SymbolWriter
writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void
>expr : Expression
>Expression : Expression
>enclosingDeclaration : Node
>Node : Node
>flags : TypeFormatFlags
>TypeFormatFlags : TypeFormatFlags
>writer : SymbolWriter
>SymbolWriter : SymbolWriter
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
@@ -980,6 +980,7 @@ declare module "typescript" {
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
@@ -3217,6 +3217,17 @@ declare module "typescript" {
>flags : TypeFormatFlags
>TypeFormatFlags : TypeFormatFlags
>writer : SymbolWriter
>SymbolWriter : SymbolWriter
writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void
>expr : Expression
>Expression : Expression
>enclosingDeclaration : Node
>Node : Node
>flags : TypeFormatFlags
>TypeFormatFlags : TypeFormatFlags
>writer : SymbolWriter
>SymbolWriter : SymbolWriter
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
@@ -981,6 +981,7 @@ declare module "typescript" {
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
@@ -3167,6 +3167,17 @@ declare module "typescript" {
>flags : TypeFormatFlags
>TypeFormatFlags : TypeFormatFlags
>writer : SymbolWriter
>SymbolWriter : SymbolWriter
writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void
>expr : Expression
>Expression : Expression
>enclosingDeclaration : Node
>Node : Node
>flags : TypeFormatFlags
>TypeFormatFlags : TypeFormatFlags
>writer : SymbolWriter
>SymbolWriter : SymbolWriter
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
@@ -1018,6 +1018,7 @@ declare module "typescript" {
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
@@ -3340,6 +3340,17 @@ declare module "typescript" {
>flags : TypeFormatFlags
>TypeFormatFlags : TypeFormatFlags
>writer : SymbolWriter
>SymbolWriter : SymbolWriter
writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void
>expr : Expression
>Expression : Expression
>enclosingDeclaration : Node
>Node : Node
>flags : TypeFormatFlags
>TypeFormatFlags : TypeFormatFlags
>writer : SymbolWriter
>SymbolWriter : SymbolWriter
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
@@ -0,0 +1,8 @@
tests/cases/compiler/declarationEmitDefaultExport1.ts(1,22): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
==== tests/cases/compiler/declarationEmitDefaultExport1.ts (1 errors) ====
export default class C {
~
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
}
@@ -0,0 +1,16 @@
//// [declarationEmitDefaultExport1.ts]
export default class C {
}
//// [declarationEmitDefaultExport1.js]
var C = (function () {
function C() {
}
return C;
})();
module.exports = C;
//// [declarationEmitDefaultExport1.d.ts]
export default class C {
}
@@ -0,0 +1,8 @@
tests/cases/compiler/declarationEmitDefaultExport2.ts(1,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
==== tests/cases/compiler/declarationEmitDefaultExport2.ts (1 errors) ====
export default class {
~~~~~~
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
}
@@ -0,0 +1,16 @@
//// [declarationEmitDefaultExport2.ts]
export default class {
}
//// [declarationEmitDefaultExport2.js]
var _default = (function () {
function _default() {
}
return _default;
})();
module.exports = _default;
//// [declarationEmitDefaultExport2.d.ts]
export default class {
}
@@ -0,0 +1,9 @@
tests/cases/compiler/declarationEmitDefaultExport3.ts(1,25): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
==== tests/cases/compiler/declarationEmitDefaultExport3.ts (1 errors) ====
export default function foo() {
~~~
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
return ""
}
@@ -0,0 +1,14 @@
//// [declarationEmitDefaultExport3.ts]
export default function foo() {
return ""
}
//// [declarationEmitDefaultExport3.js]
function foo() {
return "";
}
module.exports = foo;
//// [declarationEmitDefaultExport3.d.ts]
export default function foo(): string;
@@ -0,0 +1,9 @@
tests/cases/compiler/declarationEmitDefaultExport4.ts(1,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
==== tests/cases/compiler/declarationEmitDefaultExport4.ts (1 errors) ====
export default function () {
~~~~~~
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
return 1;
}
@@ -0,0 +1,14 @@
//// [declarationEmitDefaultExport4.ts]
export default function () {
return 1;
}
//// [declarationEmitDefaultExport4.js]
function _default() {
return 1;
}
module.exports = _default;
//// [declarationEmitDefaultExport4.d.ts]
export default function (): number;
@@ -0,0 +1,8 @@
tests/cases/compiler/declarationEmitDefaultExport5.ts(1,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
==== tests/cases/compiler/declarationEmitDefaultExport5.ts (1 errors) ====
export default 1 + 2;
~~~~~~~~~~~~~~~~~~~~~
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
@@ -0,0 +1,10 @@
//// [declarationEmitDefaultExport5.ts]
export default 1 + 2;
//// [declarationEmitDefaultExport5.js]
module.exports = 1 + 2;
//// [declarationEmitDefaultExport5.d.ts]
export default : number;
@@ -0,0 +1,12 @@
tests/cases/compiler/declarationEmitDefaultExport6.ts(1,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
tests/cases/compiler/declarationEmitDefaultExport6.ts(2,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
==== tests/cases/compiler/declarationEmitDefaultExport6.ts (2 errors) ====
export class A {}
~
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
export default new A();
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2309: An export assignment cannot be used in a module with other exported elements.
@@ -0,0 +1,19 @@
//// [declarationEmitDefaultExport6.ts]
export class A {}
export default new A();
//// [declarationEmitDefaultExport6.js]
var A = (function () {
function A() {
}
return A;
})();
exports.A = A;
module.exports = new A();
//// [declarationEmitDefaultExport6.d.ts]
export declare class A {
}
export default : A;
@@ -0,0 +1,12 @@
tests/cases/compiler/declarationEmitDefaultExport7.ts(2,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
tests/cases/compiler/declarationEmitDefaultExport7.ts(2,1): error TS4081: Default export of the module has or is using private name 'A'.
==== tests/cases/compiler/declarationEmitDefaultExport7.ts (2 errors) ====
class A {}
export default new A();
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4081: Default export of the module has or is using private name 'A'.
@@ -0,0 +1,12 @@
//// [declarationEmitDefaultExport7.ts]
class A {}
export default new A();
//// [declarationEmitDefaultExport7.js]
var A = (function () {
function A() {
}
return A;
})();
module.exports = new A();
@@ -0,0 +1,4 @@
// @declaration: true
// @target: es6
export default class C {
}
@@ -0,0 +1,4 @@
// @declaration: true
// @target: es6
export default class {
}
@@ -0,0 +1,5 @@
// @declaration: true
// @target: es6
export default function foo() {
return ""
}
@@ -0,0 +1,5 @@
// @declaration: true
// @target: es6
export default function () {
return 1;
}
@@ -0,0 +1,3 @@
// @declaration: true
// @target: es6
export default 1 + 2;
@@ -0,0 +1,4 @@
// @declaration: true
// @target: es6
export class A {}
export default new A();
@@ -0,0 +1,4 @@
// @declaration: true
// @target: es6
class A {}
export default new A();