mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Wip-type check dynamic import
This commit is contained in:
@@ -2317,7 +2317,7 @@ namespace ts {
|
||||
// A common practice in node modules is to set 'export = module.exports = {}', this ensures that 'exports'
|
||||
// is still pointing to 'module.exports'.
|
||||
// We do not want to consider this as 'export=' since a module can have only one of these.
|
||||
// Similarlly we do not want to treat 'module.exports = exports' as an 'export='.
|
||||
// Similarly we do not want to treat 'module.exports = exports' as an 'export='.
|
||||
const assignedExpression = getRightMostAssignedExpression(node.right);
|
||||
if (isEmptyObjectLiteral(assignedExpression) || isExportsOrModuleExportsOrAlias(assignedExpression)) {
|
||||
// Mark it as a module in case there are no other exports in the file
|
||||
|
||||
@@ -14862,6 +14862,14 @@ namespace ts {
|
||||
return getReturnTypeOfSignature(signature);
|
||||
}
|
||||
|
||||
function checkImportCallExpression(node: ImportCallExpression): Type {
|
||||
// resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal
|
||||
const moduleSymbol = resolveExternalModuleName(node, node.specifier);
|
||||
if (moduleSymbol) {
|
||||
}
|
||||
return createPromiseReturnType(node, anyType);
|
||||
}
|
||||
|
||||
function isCommonJsRequire(node: Node) {
|
||||
if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) {
|
||||
return false;
|
||||
@@ -15068,7 +15076,7 @@ namespace ts {
|
||||
return emptyObjectType;
|
||||
}
|
||||
|
||||
function createPromiseReturnType(func: FunctionLikeDeclaration, promisedType: Type) {
|
||||
function createPromiseReturnType(func: FunctionLikeDeclaration | ImportCallExpression, promisedType: Type) {
|
||||
const promiseType = createPromiseType(promisedType);
|
||||
if (promiseType === emptyObjectType) {
|
||||
error(func, Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option);
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace ts {
|
||||
visitNodes(cbNodes, (<CallExpression>node).typeArguments) ||
|
||||
visitNodes(cbNodes, (<CallExpression>node).arguments);
|
||||
case SyntaxKind.ImportCallExpression:
|
||||
return visitNode(cbNode, (<ImportCall>node).expression);
|
||||
return visitNode(cbNode, (<ImportCallExpression>node).specifier);
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
return visitNode(cbNode, (<TaggedTemplateExpression>node).tag) ||
|
||||
visitNode(cbNode, (<TaggedTemplateExpression>node).template);
|
||||
@@ -3695,8 +3695,8 @@ namespace ts {
|
||||
// var foo3 = require("subfolder
|
||||
// import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression
|
||||
const importCall = parseImportCall();
|
||||
if (importCall.expression.kind === SyntaxKind.StringLiteral) {
|
||||
(sourceFile.imports || (sourceFile.imports = [])).push(importCall.expression as StringLiteral);
|
||||
if (importCall.specifier.kind === SyntaxKind.StringLiteral) {
|
||||
(sourceFile.imports || (sourceFile.imports = [])).push(importCall.specifier as StringLiteral);
|
||||
}
|
||||
return importCall;
|
||||
}
|
||||
@@ -3774,11 +3774,11 @@ namespace ts {
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseImportCall(): ImportCall {
|
||||
const importCallExpr = <ImportCall>createNode(SyntaxKind.ImportCallExpression);
|
||||
function parseImportCall(): ImportCallExpression {
|
||||
const importCallExpr = <ImportCallExpression>createNode(SyntaxKind.ImportCallExpression);
|
||||
parseExpected(SyntaxKind.ImportKeyword);
|
||||
parseExpected(SyntaxKind.OpenParenToken);
|
||||
importCallExpr.expression = parseAssignmentExpressionOrHigher();
|
||||
importCallExpr.specifier = parseAssignmentExpressionOrHigher();
|
||||
parseExpected(SyntaxKind.CloseParenToken);
|
||||
return finishNode(importCallExpr);
|
||||
}
|
||||
|
||||
@@ -1447,9 +1447,9 @@ namespace ts {
|
||||
expression: SuperExpression;
|
||||
}
|
||||
|
||||
export interface ImportCall extends LeftHandSideExpression, Declaration {
|
||||
export interface ImportCallExpression extends LeftHandSideExpression, Declaration {
|
||||
kind: SyntaxKind.ImportCallExpression;
|
||||
expression: Expression;
|
||||
specifier: Expression;
|
||||
}
|
||||
|
||||
export interface ExpressionWithTypeArguments extends TypeNode {
|
||||
|
||||
@@ -662,7 +662,7 @@ namespace ts {
|
||||
return n.kind === SyntaxKind.CallExpression && (<CallExpression>n).expression.kind === SyntaxKind.SuperKeyword;
|
||||
}
|
||||
|
||||
export function isImportCall(n: Node): n is ImportCall {
|
||||
export function isImportCall(n: Node): n is ImportCallExpression {
|
||||
return n.kind === SyntaxKind.ImportCallExpression;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user