Revert "Support an optional type annotation on export default statement"

This reverts commit a6a8a96249.
This commit is contained in:
Mohamed Hegazy
2015-04-09 16:32:23 -07:00
parent 55d6e10687
commit afe35c810a
16 changed files with 11 additions and 141 deletions
+1 -1
View File
@@ -539,7 +539,7 @@ module ts {
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.ExportAssignment:
if ((<ExportAssignment>node).expression && (<ExportAssignment>node).expression.kind === SyntaxKind.Identifier) {
if ((<ExportAssignment>node).expression.kind === SyntaxKind.Identifier) {
// An export default clause with an identifier exports all meanings of that identifier
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes);
}
+7 -25
View File
@@ -682,7 +682,7 @@ module ts {
}
function getTargetOfExportAssignment(node: ExportAssignment): Symbol {
return node.expression && resolveEntityName(<Identifier>node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
return resolveEntityName(<Identifier>node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
}
function getTargetOfAliasDeclaration(node: Declaration): Symbol {
@@ -748,7 +748,7 @@ module ts {
if (!links.referenced) {
links.referenced = true;
let node = getDeclarationOfAliasSymbol(symbol);
if (node.kind === SyntaxKind.ExportAssignment && (<ExportAssignment>node).expression) {
if (node.kind === SyntaxKind.ExportAssignment) {
// export default <symbol>
checkExpressionCached((<ExportAssignment>node).expression);
}
@@ -2287,16 +2287,7 @@ module ts {
}
// Handle export default expressions
if (declaration.kind === SyntaxKind.ExportAssignment) {
var exportAssignment = <ExportAssignment>declaration;
if (exportAssignment.expression) {
return links.type = checkExpression(exportAssignment.expression);
}
else if (exportAssignment.type) {
return links.type = getTypeFromTypeNodeOrHeritageClauseElement(exportAssignment.type);
}
else {
return links.type = anyType;
}
return links.type = checkExpression((<ExportAssignment>declaration).expression);
}
// Handle variable, parameter or property
links.type = resolvingType;
@@ -10599,21 +10590,12 @@ module ts {
if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) {
grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers);
}
if (node.expression) {
if (node.expression.kind === SyntaxKind.Identifier) {
markExportAsReferenced(node);
}
else {
checkExpressionCached(node.expression);
}
if (node.expression.kind === SyntaxKind.Identifier) {
markExportAsReferenced(node);
}
if (node.type) {
checkSourceElement(node.type);
if (!isInAmbientContext(node)) {
grammarErrorOnFirstToken(node.type, Diagnostics.A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration);
}
else {
checkExpressionCached(node.expression);
}
checkExternalModuleExports(container);
if (node.isExportEquals && languageVersion >= ScriptTarget.ES6) {
@@ -158,7 +158,6 @@ module ts {
An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." },
Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." },
Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." },
A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration: { code: 1201, category: DiagnosticCategory.Error, key: "A type annotation on an export statement is only allowed in an ambient external module declaration." },
Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." },
Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." },
Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." },
-4
View File
@@ -623,10 +623,6 @@
"category": "Error",
"code": 1200
},
"A type annotation on an export statement is only allowed in an ambient external module declaration.": {
"category": "Error",
"code": 1201
},
"Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead.": {
"category": "Error",
"code": 1202
+2 -9
View File
@@ -299,8 +299,7 @@ module ts {
case SyntaxKind.ExportAssignment:
return visitNodes(cbNodes, node.decorators) ||
visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, (<ExportAssignment>node).expression) ||
visitNode(cbNode, (<ExportAssignment>node).type);
visitNode(cbNode, (<ExportAssignment>node).expression);
case SyntaxKind.TemplateExpression:
return visitNode(cbNode, (<TemplateExpression>node).head) || visitNodes(cbNodes, (<TemplateExpression>node).templateSpans);
case SyntaxKind.TemplateSpan:
@@ -5123,17 +5122,11 @@ module ts {
setModifiers(node, modifiers);
if (parseOptional(SyntaxKind.EqualsToken)) {
node.isExportEquals = true;
node.expression = parseAssignmentExpressionOrHigher();
}
else {
parseExpected(SyntaxKind.DefaultKeyword);
if (parseOptional(SyntaxKind.ColonToken)) {
node.type = parseType();
}
else {
node.expression = parseAssignmentExpressionOrHigher();
}
}
node.expression = parseAssignmentExpressionOrHigher();
parseSemicolon();
return finishNode(node);
}
+1 -2
View File
@@ -975,8 +975,7 @@ module ts {
export interface ExportAssignment extends Declaration, ModuleElement {
isExportEquals?: boolean;
expression?: Expression;
type?: TypeNode;
expression: Expression;
}
export interface FileReference extends TextRange {
-4
View File
@@ -173,10 +173,6 @@ module ts.BreakpointResolver {
return textSpan(node, (<ThrowStatement>node).expression);
case SyntaxKind.ExportAssignment:
if (!(<ExportAssignment>node).expression) {
return undefined;
}
// span on export = id
return textSpan(node, (<ExportAssignment>node).expression);
@@ -1,8 +0,0 @@
tests/cases/compiler/exportDefaultTypeAnnoation.ts(2,18): error TS1201: A type annotation on an export statement is only allowed in an ambient external module declaration.
==== tests/cases/compiler/exportDefaultTypeAnnoation.ts (1 errors) ====
export default : number;
~~~~~~
!!! error TS1201: A type annotation on an export statement is only allowed in an ambient external module declaration.
@@ -1,6 +0,0 @@
//// [exportDefaultTypeAnnoation.ts]
export default : number;
//// [exportDefaultTypeAnnoation.js]
exports.default = ;
@@ -1,7 +0,0 @@
//// [exportDefaultTypeAnnoation2.ts]
declare module "mod" {
export default : number;
}
//// [exportDefaultTypeAnnoation2.js]
@@ -1,6 +0,0 @@
=== tests/cases/compiler/exportDefaultTypeAnnoation2.ts ===
No type information for this code.declare module "mod" {
No type information for this code. export default : number;
No type information for this code.}
No type information for this code.
@@ -1,21 +0,0 @@
tests/cases/compiler/reference1.ts(2,5): error TS2322: Type 'number' is not assignable to type 'string'.
tests/cases/compiler/reference2.ts(2,5): error TS2322: Type 'number' is not assignable to type 'string'.
==== tests/cases/compiler/mod.d.ts (0 errors) ====
declare module "mod" {
export default : number;
}
==== tests/cases/compiler/reference1.ts (1 errors) ====
import d from "mod";
var s: string = d; // Error
~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
==== tests/cases/compiler/reference2.ts (1 errors) ====
import { default as d } from "mod";
var s: string = d; // Error
~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
@@ -1,22 +0,0 @@
//// [tests/cases/compiler/exportDefaultTypeAnnoation3.ts] ////
//// [mod.d.ts]
declare module "mod" {
export default : number;
}
//// [reference1.ts]
import d from "mod";
var s: string = d; // Error
//// [reference2.ts]
import { default as d } from "mod";
var s: string = d; // Error
//// [reference1.js]
var mod_1 = require("mod");
var s = mod_1.default; // Error
//// [reference2.js]
var mod_1 = require("mod");
var s = mod_1.default; // Error
@@ -1,4 +0,0 @@
// @target: es5
// @module: commonjs
export default : number;
@@ -1,6 +0,0 @@
// @target: es5
// @module: commonjs
declare module "mod" {
export default : number;
}
@@ -1,15 +0,0 @@
// @target: es5
// @module: commonjs
// @fileName: mod.d.ts
declare module "mod" {
export default : number;
}
// @fileName: reference1.ts
import d from "mod";
var s: string = d; // Error
// @fileName: reference2.ts
import { default as d } from "mod";
var s: string = d; // Error