mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Check for instantiation on export default in ES6
This commit is contained in:
parent
f90253f73e
commit
86d561d2be
@ -3924,26 +3924,28 @@ module ts {
|
||||
}
|
||||
|
||||
function emitExportAssignment(node: ExportAssignment) {
|
||||
if (languageVersion >= ScriptTarget.ES6) {
|
||||
writeLine();
|
||||
emitStart(node);
|
||||
write("export default ");
|
||||
var expression = node.expression;
|
||||
emit(expression);
|
||||
if (expression.kind !== SyntaxKind.FunctionDeclaration &&
|
||||
expression.kind !== SyntaxKind.ClassDeclaration) {
|
||||
write(";");
|
||||
if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) {
|
||||
if (languageVersion >= ScriptTarget.ES6) {
|
||||
writeLine();
|
||||
emitStart(node);
|
||||
write("export default ");
|
||||
var expression = node.expression;
|
||||
emit(expression);
|
||||
if (expression.kind !== SyntaxKind.FunctionDeclaration &&
|
||||
expression.kind !== SyntaxKind.ClassDeclaration) {
|
||||
write(";");
|
||||
}
|
||||
emitEnd(node);
|
||||
}
|
||||
else {
|
||||
writeLine();
|
||||
emitStart(node);
|
||||
emitContainingModuleName(node);
|
||||
write(".default = ");
|
||||
emit(node.expression);
|
||||
write(";");
|
||||
emitEnd(node);
|
||||
}
|
||||
emitEnd(node);
|
||||
}
|
||||
else if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) {
|
||||
writeLine();
|
||||
emitStart(node);
|
||||
emitContainingModuleName(node);
|
||||
write(".default = ");
|
||||
emit(node.expression);
|
||||
write(";");
|
||||
emitEnd(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,4 +5,3 @@ export = a;
|
||||
|
||||
//// [es6ExportAssignment.js]
|
||||
var a = 10;
|
||||
export default a;
|
||||
|
||||
@ -8,7 +8,6 @@ export = f;
|
||||
//// [es6ExportEquals.js]
|
||||
export function f() {
|
||||
}
|
||||
export default f;
|
||||
|
||||
|
||||
//// [es6ExportEquals.d.ts]
|
||||
|
||||
@ -10,5 +10,4 @@ import a = require("server");
|
||||
|
||||
//// [server.js]
|
||||
var a = 10;
|
||||
export default a;
|
||||
//// [client.js]
|
||||
|
||||
@ -12,7 +12,6 @@ export = a;
|
||||
export var a = 10;
|
||||
//// [es6ImportNamedImportInExportAssignment_1.js]
|
||||
import { a } from "es6ImportNamedImportInExportAssignment_0";
|
||||
export default a;
|
||||
|
||||
|
||||
//// [es6ImportNamedImportInExportAssignment_0.d.ts]
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
//// [exportDefaultForNonInstantiatedModule.ts]
|
||||
|
||||
module m {
|
||||
export interface foo {
|
||||
}
|
||||
}
|
||||
// Should not be emitted
|
||||
export default m;
|
||||
|
||||
//// [exportDefaultForNonInstantiatedModule.js]
|
||||
@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/exportDefaultForNonInstantiatedModule.ts ===
|
||||
|
||||
module m {
|
||||
>m : unknown
|
||||
|
||||
export interface foo {
|
||||
>foo : foo
|
||||
}
|
||||
}
|
||||
// Should not be emitted
|
||||
export default m;
|
||||
>m : unknown
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
// @target: ES6
|
||||
|
||||
module m {
|
||||
export interface foo {
|
||||
}
|
||||
}
|
||||
// Should not be emitted
|
||||
export default m;
|
||||
Loading…
x
Reference in New Issue
Block a user