Skip to content

Commit 56f4b2e

Browse files
Provide an error when using 'import.meta' without setting 'esnext'.
1 parent 7c0f249 commit 56f4b2e

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/compiler/checker.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18702,10 +18702,7 @@ namespace ts {
1870218702
}
1870318703

1870418704
if (node.keywordToken === SyntaxKind.ImportKeyword) {
18705-
const file = getSourceFileOfNode(node);
18706-
Debug.assert(!!(file.flags & NodeFlags.PossiblyContainsImportMeta), "Containing file is missing import meta node flag.");
18707-
Debug.assert(!!file.externalModuleIndicator, "Containing file should be a module.");
18708-
return node.name.escapedText === "meta" ? getGlobalImportMetaType() : unknownType;
18705+
return checkImportMetaProperty(node);
1870918706
}
1871018707
}
1871118708

@@ -18725,6 +18722,16 @@ namespace ts {
1872518722
}
1872618723
}
1872718724

18725+
function checkImportMetaProperty(node: MetaProperty) {
18726+
if (languageVersion < ScriptTarget.ESNext && modulekind < ModuleKind.ESNext) {
18727+
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_using_ESNext_for_the_target_and_module_compiler_options);
18728+
}
18729+
const file = getSourceFileOfNode(node);
18730+
Debug.assert(!!(file.flags & NodeFlags.PossiblyContainsImportMeta), "Containing file is missing import meta node flag.");
18731+
Debug.assert(!!file.externalModuleIndicator, "Containing file should be a module.");
18732+
return node.name.escapedText === "meta" ? getGlobalImportMetaType() : unknownType;
18733+
}
18734+
1872818735
function getTypeOfParameter(symbol: Symbol) {
1872918736
const type = getTypeOfSymbol(symbol);
1873018737
if (strictNullChecks) {

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,10 @@
967967
"category": "Error",
968968
"code": 1342
969969
},
970+
"The 'import.meta' meta-property is only allowed using 'ESNext' for the 'target' and 'module' compiler options.": {
971+
"category": "Error",
972+
"code": 1343
973+
},
970974

971975
"Duplicate identifier '{0}'.": {
972976
"category": "Error",

0 commit comments

Comments
 (0)