MCPcopy Index your code
hub / github.com/nodejs/node / checkAssertClause

Function checkAssertClause

test/fixtures/snapshot/typescript.js:85243–85270  ·  view source on GitHub ↗
(declaration)

Source from the content-addressed store, hash-verified

85241 }
85242 }
85243 function checkAssertClause(declaration) {
85244 var _a;
85245 if (declaration.assertClause) {
85246 var validForTypeAssertions = ts.isExclusivelyTypeOnlyImportOrExport(declaration);
85247 var override = ts.getResolutionModeOverrideForClause(declaration.assertClause, validForTypeAssertions ? grammarErrorOnNode : undefined);
85248 if (validForTypeAssertions && override) {
85249 if (!ts.isNightly()) {
85250 grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next);
85251 }
85252 if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) {
85253 return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext);
85254 }
85255 return; // Other grammar checks do not apply to type-only imports with resolution mode assertions
85256 }
85257 var mode = (moduleKind === ts.ModuleKind.NodeNext) && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier);
85258 if (mode !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.ESNext) {
85259 return grammarErrorOnNode(declaration.assertClause, moduleKind === ts.ModuleKind.NodeNext
85260 ? ts.Diagnostics.Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls
85261 : ts.Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_or_nodenext);
85262 }
85263 if (ts.isImportDeclaration(declaration) ? (_a = declaration.importClause) === null || _a === void 0 ? void 0 : _a.isTypeOnly : declaration.isTypeOnly) {
85264 return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports);
85265 }
85266 if (override) {
85267 return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_can_only_be_set_for_type_only_imports);
85268 }
85269 }
85270 }
85271 function checkImportDeclaration(node) {
85272 if (checkGrammarModuleElementContext(node, ts.isInJSFile(node) ? ts.Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module : ts.Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)) {
85273 // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.

Callers 2

checkImportDeclarationFunction · 0.85
checkExportDeclarationFunction · 0.85

Calls 2

grammarErrorOnNodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…