-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parsing, binding, checking of export default with function/class
- Loading branch information
1 parent
74acbe9
commit 9af8ae4
Showing
6 changed files
with
73 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8268,7 +8268,7 @@ module ts { | |
// Do not use hasDynamicName here, because that returns false for well known symbols. | ||
// We want to perform checkComputedPropertyName for all computed properties, including | ||
// well known symbols. | ||
if (node.name.kind === SyntaxKind.ComputedPropertyName) { | ||
if (node.name && node.name.kind === SyntaxKind.ComputedPropertyName) { | ||
// This check will account for methods in class/interface declarations, | ||
// as well as accessors in classes/object literals | ||
checkComputedPropertyName(<ComputedPropertyName>node.name); | ||
|
@@ -8998,10 +8998,12 @@ module ts { | |
// Grammar checking | ||
checkGrammarClassDeclarationHeritageClauses(node); | ||
|
||
checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0); | ||
if (node.name) { | ||
checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0); | ||
checkCollisionWithCapturedThisVariable(node, node.name); | ||
checkCollisionWithRequireExportsInGeneratedCode(node, node.name); | ||
} | ||
checkTypeParameters(node.typeParameters); | ||
checkCollisionWithCapturedThisVariable(node, node.name); | ||
checkCollisionWithRequireExportsInGeneratedCode(node, node.name); | ||
checkExportsOnMergedDeclarations(node); | ||
var symbol = getSymbolOfNode(node); | ||
var type = <InterfaceType>getDeclaredTypeOfSymbol(symbol); | ||
|
@@ -9014,9 +9016,9 @@ module ts { | |
if (type.baseTypes.length) { | ||
if (produceDiagnostics) { | ||
var baseType = type.baseTypes[0]; | ||
checkTypeAssignableTo(type, baseType, node.name, Diagnostics.Class_0_incorrectly_extends_base_class_1); | ||
checkTypeAssignableTo(type, baseType, node.name || node, Diagnostics.Class_0_incorrectly_extends_base_class_1); | ||
This comment has been minimized.
Sorry, something went wrong.
CyrusNajmabadi
Contributor
|
||
var staticBaseType = getTypeOfSymbol(baseType.symbol); | ||
checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name, | ||
checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name || node, | ||
Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); | ||
if (baseType.symbol !== resolveEntityName(baseTypeNode.typeName, SymbolFlags.Value)) { | ||
error(baseTypeNode, Diagnostics.Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0, typeToString(baseType)); | ||
|
@@ -9038,7 +9040,7 @@ module ts { | |
if (t !== unknownType) { | ||
var declaredType = (t.flags & TypeFlags.Reference) ? (<TypeReference>t).target : t; | ||
if (declaredType.flags & (TypeFlags.Class | TypeFlags.Interface)) { | ||
checkTypeAssignableTo(type, t, node.name, Diagnostics.Class_0_incorrectly_implements_interface_1); | ||
checkTypeAssignableTo(type, t, node.name || node, Diagnostics.Class_0_incorrectly_implements_interface_1); | ||
} | ||
else { | ||
error(typeRefNode, Diagnostics.A_class_may_only_implement_another_class_or_interface); | ||
|
@@ -10414,6 +10416,10 @@ module ts { | |
|
||
function generateNames(node: Node) { | ||
switch (node.kind) { | ||
case SyntaxKind.FunctionDeclaration: | ||
case SyntaxKind.ClassDeclaration: | ||
generateNameForFunctionOrClassDeclaration(<Declaration>node); | ||
break; | ||
case SyntaxKind.ModuleDeclaration: | ||
generateNameForModuleOrEnum(<ModuleDeclaration>node); | ||
generateNames((<ModuleDeclaration>node).body); | ||
|
@@ -10427,6 +10433,9 @@ module ts { | |
case SyntaxKind.ExportDeclaration: | ||
generateNameForExportDeclaration(<ExportDeclaration>node); | ||
break; | ||
case SyntaxKind.ExportAssignment: | ||
generateNameForExportAssignment(<ExportAssignment>node); | ||
break; | ||
case SyntaxKind.SourceFile: | ||
case SyntaxKind.ModuleBlock: | ||
forEach((<SourceFile | ModuleBlock>node).statements, generateNames); | ||
|
@@ -10464,6 +10473,12 @@ module ts { | |
getNodeLinks(node).generatedName = unescapeIdentifier(name); | ||
} | ||
|
||
function generateNameForFunctionOrClassDeclaration(node: Declaration) { | ||
if (!node.name) { | ||
assignGeneratedName(node, makeUniqueName("default")); | ||
} | ||
} | ||
|
||
function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) { | ||
if (node.name.kind === SyntaxKind.Identifier) { | ||
var name = node.name.text; | ||
|
@@ -10490,9 +10505,15 @@ module ts { | |
generateNameForImportOrExportDeclaration(node); | ||
} | ||
} | ||
|
||
function generateNameForExportAssignment(node: ExportAssignment) { | ||
if (node.expression.kind !== SyntaxKind.Identifier) { | ||
assignGeneratedName(node, makeUniqueName("default")); | ||
} | ||
} | ||
} | ||
|
||
function getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration) { | ||
function getGeneratedNameForNode(node: Node) { | ||
var links = getNodeLinks(node); | ||
if (!links.generatedName) { | ||
getGeneratedNamesForSourceFile(getSourceFile(node)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -901,6 +901,7 @@ module ts { | |
case SyntaxKind.ExportKeyword: | ||
case SyntaxKind.DeclareKeyword: | ||
case SyntaxKind.ConstKeyword: | ||
case SyntaxKind.DefaultKeyword: | ||
This comment has been minimized.
Sorry, something went wrong.
CyrusNajmabadi
Contributor
|
||
return true; | ||
} | ||
return false; | ||
|
I think i'd prefer an assert over just returning undefined. If you have a class/function, it better have a name if it doesn't have the 'default' modifier on it.