(node)
| 85474 | } |
| 85475 | } |
| 85476 | function checkExportAssignment(node) { |
| 85477 | var illegalContextMessage = node.isExportEquals |
| 85478 | ? ts.Diagnostics.An_export_assignment_must_be_at_the_top_level_of_a_file_or_module_declaration |
| 85479 | : ts.Diagnostics.A_default_export_must_be_at_the_top_level_of_a_file_or_module_declaration; |
| 85480 | if (checkGrammarModuleElementContext(node, illegalContextMessage)) { |
| 85481 | // If we hit an export assignment in an illegal context, just bail out to avoid cascading errors. |
| 85482 | return; |
| 85483 | } |
| 85484 | var container = node.parent.kind === 305 /* SyntaxKind.SourceFile */ ? node.parent : node.parent.parent; |
| 85485 | if (container.kind === 261 /* SyntaxKind.ModuleDeclaration */ && !ts.isAmbientModule(container)) { |
| 85486 | if (node.isExportEquals) { |
| 85487 | error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace); |
| 85488 | } |
| 85489 | else { |
| 85490 | error(node, ts.Diagnostics.A_default_export_can_only_be_used_in_an_ECMAScript_style_module); |
| 85491 | } |
| 85492 | return; |
| 85493 | } |
| 85494 | // Grammar checking |
| 85495 | if (!checkGrammarDecoratorsAndModifiers(node) && ts.hasEffectiveModifiers(node)) { |
| 85496 | grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); |
| 85497 | } |
| 85498 | var typeAnnotationNode = ts.getEffectiveTypeAnnotationNode(node); |
| 85499 | if (typeAnnotationNode) { |
| 85500 | checkTypeAssignableTo(checkExpressionCached(node.expression), getTypeFromTypeNode(typeAnnotationNode), node.expression); |
| 85501 | } |
| 85502 | if (node.expression.kind === 79 /* SyntaxKind.Identifier */) { |
| 85503 | var id = node.expression; |
| 85504 | var sym = resolveEntityName(id, 67108863 /* SymbolFlags.All */, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, node); |
| 85505 | if (sym) { |
| 85506 | markAliasReferenced(sym, id); |
| 85507 | // If not a value, we're interpreting the identifier as a type export, along the lines of (`export { Id as default }`) |
| 85508 | var target = sym.flags & 2097152 /* SymbolFlags.Alias */ ? resolveAlias(sym) : sym; |
| 85509 | if (target === unknownSymbol || target.flags & 111551 /* SymbolFlags.Value */) { |
| 85510 | // However if it is a value, we need to check it's being used correctly |
| 85511 | checkExpressionCached(node.expression); |
| 85512 | } |
| 85513 | } |
| 85514 | else { |
| 85515 | checkExpressionCached(node.expression); // doesn't resolve, check as expression to mark as error |
| 85516 | } |
| 85517 | if (ts.getEmitDeclarations(compilerOptions)) { |
| 85518 | collectLinkedAliases(node.expression, /*setVisibility*/ true); |
| 85519 | } |
| 85520 | } |
| 85521 | else { |
| 85522 | checkExpressionCached(node.expression); |
| 85523 | } |
| 85524 | checkExternalModuleExports(container); |
| 85525 | if ((node.flags & 16777216 /* NodeFlags.Ambient */) && !ts.isEntityNameExpression(node.expression)) { |
| 85526 | grammarErrorOnNode(node.expression, ts.Diagnostics.The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context); |
| 85527 | } |
| 85528 | if (node.isExportEquals && !(node.flags & 16777216 /* NodeFlags.Ambient */)) { |
| 85529 | if (moduleKind >= ts.ModuleKind.ES2015 && ts.getSourceFileOfNode(node).impliedNodeFormat !== ts.ModuleKind.CommonJS) { |
| 85530 | // export assignment is not supported in es6 modules |
| 85531 | grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead); |
| 85532 | } |
| 85533 | else if (moduleKind === ts.ModuleKind.System) { |
no test coverage detected
searching dependent graphs…