Provide an error when using 'import.meta' without setting 'esnext'.

This commit is contained in:
Daniel Rosenwasser
2018-04-10 16:12:00 -07:00
parent 7c0f249619
commit 56f4b2eea4
2 changed files with 15 additions and 4 deletions

View File

@@ -18702,10 +18702,7 @@ namespace ts {
}
if (node.keywordToken === SyntaxKind.ImportKeyword) {
const file = getSourceFileOfNode(node);
Debug.assert(!!(file.flags & NodeFlags.PossiblyContainsImportMeta), "Containing file is missing import meta node flag.");
Debug.assert(!!file.externalModuleIndicator, "Containing file should be a module.");
return node.name.escapedText === "meta" ? getGlobalImportMetaType() : unknownType;
return checkImportMetaProperty(node);
}
}
@@ -18725,6 +18722,16 @@ namespace ts {
}
}
function checkImportMetaProperty(node: MetaProperty) {
if (languageVersion < ScriptTarget.ESNext && modulekind < ModuleKind.ESNext) {
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_using_ESNext_for_the_target_and_module_compiler_options);
}
const file = getSourceFileOfNode(node);
Debug.assert(!!(file.flags & NodeFlags.PossiblyContainsImportMeta), "Containing file is missing import meta node flag.");
Debug.assert(!!file.externalModuleIndicator, "Containing file should be a module.");
return node.name.escapedText === "meta" ? getGlobalImportMetaType() : unknownType;
}
function getTypeOfParameter(symbol: Symbol) {
const type = getTypeOfSymbol(symbol);
if (strictNullChecks) {

View File

@@ -967,6 +967,10 @@
"category": "Error",
"code": 1342
},
"The 'import.meta' meta-property is only allowed using 'ESNext' for the 'target' and 'module' compiler options.": {
"category": "Error",
"code": 1343
},
"Duplicate identifier '{0}'.": {
"category": "Error",