Skip to content

Commit ccc60c8

Browse files
authored
Revert "[Master] wip-dynamic import" (#16264)
1 parent 9d16d34 commit ccc60c8

File tree

169 files changed

+103
-5271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+103
-5271
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ namespace ts {
23332333
// A common practice in node modules is to set 'export = module.exports = {}', this ensures that 'exports'
23342334
// is still pointing to 'module.exports'.
23352335
// We do not want to consider this as 'export=' since a module can have only one of these.
2336-
// Similarly we do not want to treat 'module.exports = exports' as an 'export='.
2336+
// Similarlly we do not want to treat 'module.exports = exports' as an 'export='.
23372337
const assignedExpression = getRightMostAssignedExpression(node.right);
23382338
if (isEmptyObjectLiteral(assignedExpression) || isExportsOrModuleExportsOrAlias(assignedExpression)) {
23392339
// Mark it as a module in case there are no other exports in the file
@@ -2741,10 +2741,6 @@ namespace ts {
27412741
transformFlags |= TransformFlags.AssertES2015;
27422742
}
27432743

2744-
if (expression.kind === SyntaxKind.ImportKeyword) {
2745-
transformFlags |= TransformFlags.ContainsDynamicImport;
2746-
}
2747-
27482744
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
27492745
return transformFlags & ~TransformFlags.ArrayLiteralOrCallOrNewExcludes;
27502746
}

src/compiler/checker.ts

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8356,12 +8356,6 @@ namespace ts {
83568356
/**
83578357
* This is *not* a bi-directional relationship.
83588358
* If one needs to check both directions for comparability, use a second call to this function or 'checkTypeComparableTo'.
8359-
*
8360-
* A type S is comparable to a type T if some (but not necessarily all) of the possible values of S are also possible values of T.
8361-
* It is used to check following cases:
8362-
* - the types of the left and right sides of equality/inequality operators (`===`, `!==`, `==`, `!=`).
8363-
* - the types of `case` clause expressions and their respective `switch` expressions.
8364-
* - the type of an expression in a type assertion with the type being asserted.
83658359
*/
83668360
function isTypeComparableTo(source: Type, target: Type): boolean {
83678361
return isTypeRelatedTo(source, target, comparableRelation);
@@ -16164,35 +16158,6 @@ namespace ts {
1616416158
return getReturnTypeOfSignature(signature);
1616516159
}
1616616160

16167-
function checkImportCallExpression(node: ImportCall): Type {
16168-
// Check grammar of dynamic import
16169-
checkGrammarArguments(node, node.arguments) || checkGrammarImportCallExpression(node);
16170-
16171-
if (node.arguments.length === 0) {
16172-
return createPromiseReturnType(node, anyType);
16173-
}
16174-
const specifier = node.arguments[0];
16175-
const specifierType = checkExpressionCached(specifier);
16176-
// Even though multiple arugments is grammatically incorrect, type-check extra arguments for completion
16177-
for (let i = 1; i < node.arguments.length; ++i) {
16178-
checkExpressionCached(node.arguments[i]);
16179-
}
16180-
16181-
if (specifierType.flags & TypeFlags.Undefined || specifierType.flags & TypeFlags.Null || !isTypeAssignableTo(specifierType, stringType)) {
16182-
error(specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType));
16183-
}
16184-
16185-
// resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal
16186-
const moduleSymbol = resolveExternalModuleName(node, specifier);
16187-
if (moduleSymbol) {
16188-
const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true);
16189-
if (esModuleSymbol) {
16190-
return createPromiseReturnType(node, getTypeOfSymbol(esModuleSymbol));
16191-
}
16192-
}
16193-
return createPromiseReturnType(node, anyType);
16194-
}
16195-
1619616161
function isCommonJsRequire(node: Node) {
1619716162
if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) {
1619816163
return false;
@@ -16399,18 +16364,14 @@ namespace ts {
1639916364
return emptyObjectType;
1640016365
}
1640116366

16402-
function createPromiseReturnType(func: FunctionLikeDeclaration | ImportCall, promisedType: Type) {
16367+
function createPromiseReturnType(func: FunctionLikeDeclaration, promisedType: Type) {
1640316368
const promiseType = createPromiseType(promisedType);
1640416369
if (promiseType === emptyObjectType) {
16405-
error(func, isImportCall(func) ?
16406-
Diagnostics.A_dynamic_import_call_returns_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option :
16407-
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);
16370+
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);
1640816371
return unknownType;
1640916372
}
1641016373
else if (!getGlobalPromiseConstructorSymbol(/*reportErrors*/ true)) {
16411-
error(func, isImportCall(func) ?
16412-
Diagnostics.A_dynamic_import_call_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option :
16413-
Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option);
16374+
error(func, Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option);
1641416375
}
1641516376

1641616377
return promiseType;
@@ -17769,10 +17730,6 @@ namespace ts {
1776917730
case SyntaxKind.ElementAccessExpression:
1777017731
return checkIndexedAccess(<ElementAccessExpression>node);
1777117732
case SyntaxKind.CallExpression:
17772-
if ((<CallExpression>node).expression.kind === SyntaxKind.ImportKeyword) {
17773-
return checkImportCallExpression(<ImportCall>node);
17774-
}
17775-
/* falls through */
1777617733
case SyntaxKind.NewExpression:
1777717734
return checkCallExpression(<CallExpression>node);
1777817735
case SyntaxKind.TaggedTemplateExpression:
@@ -24698,27 +24655,6 @@ namespace ts {
2469824655
});
2469924656
return result;
2470024657
}
24701-
24702-
function checkGrammarImportCallExpression(node: ImportCall): boolean {
24703-
if (modulekind === ModuleKind.ES2015) {
24704-
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules);
24705-
}
24706-
24707-
if (node.typeArguments) {
24708-
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_have_type_arguments);
24709-
}
24710-
24711-
const arguments = node.arguments;
24712-
if (arguments.length !== 1) {
24713-
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument);
24714-
}
24715-
24716-
// see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import.
24717-
// parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import.
24718-
if (isSpreadElement(arguments[0])) {
24719-
return grammarErrorOnNode(arguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element);
24720-
}
24721-
}
2472224658
}
2472324659

2472424660
/** Like 'isDeclarationName', but returns true for LHS of `import { x as y }` or `export { x as y }`. */

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ namespace ts {
100100
"umd": ModuleKind.UMD,
101101
"es6": ModuleKind.ES2015,
102102
"es2015": ModuleKind.ES2015,
103-
"esnext": ModuleKind.ESNext
104103
}),
105104
paramType: Diagnostics.KIND,
106105
showInSimplifiedHelpView: true,
107106
category: Diagnostics.Basic_Options,
108-
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_es2015_or_ESNext,
107+
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015,
109108
},
110109
{
111110
name: "lib",

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -883,23 +883,6 @@
883883
"category": "Error",
884884
"code": 1322
885885
},
886-
"Dynamic import cannot be used when targeting ECMAScript 2015 modules.": {
887-
"category": "Error",
888-
"code": 1323
889-
},
890-
"Dynamic import must have one specifier as an argument.": {
891-
"category": "Error",
892-
"code": 1324
893-
},
894-
"Specifier of dynamic import cannot be spread element.": {
895-
"category": "Error",
896-
"code": 1325
897-
},
898-
"Dynamic import cannot have type arguments": {
899-
"category": "Error",
900-
"code": 1326
901-
},
902-
903886
"Duplicate identifier '{0}'.": {
904887
"category": "Error",
905888
"code": 2300
@@ -1944,6 +1927,10 @@
19441927
"category": "Error",
19451928
"code": 2649
19461929
},
1930+
"Cannot emit namespaced JSX elements in React.": {
1931+
"category": "Error",
1932+
"code": 2650
1933+
},
19471934
"A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums.": {
19481935
"category": "Error",
19491936
"code": 2651
@@ -2176,14 +2163,6 @@
21762163
"category": "Error",
21772164
"code": 2710
21782165
},
2179-
"A dynamic import call returns a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option.": {
2180-
"category": "Error",
2181-
"code": 2711
2182-
},
2183-
"A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.": {
2184-
"category": "Error",
2185-
"code": 2712
2186-
},
21872166

21882167
"Import declaration '{0}' is using private name '{1}'.": {
21892168
"category": "Error",
@@ -2650,7 +2629,7 @@
26502629
"category": "Message",
26512630
"code": 6015
26522631
},
2653-
"Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'.": {
2632+
"Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'.": {
26542633
"category": "Message",
26552634
"code": 6016
26562635
},
@@ -3386,11 +3365,6 @@
33863365
"category": "Error",
33873366
"code": 7035
33883367
},
3389-
"Dynamic import's specifier must be of type 'string', but here has type '{0}'.": {
3390-
"category": "Error",
3391-
"code": 7036
3392-
},
3393-
33943368
"You cannot rename this element.": {
33953369
"category": "Error",
33963370
"code": 8000

src/compiler/emitter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,6 @@ namespace ts {
676676
case SyntaxKind.SuperKeyword:
677677
case SyntaxKind.TrueKeyword:
678678
case SyntaxKind.ThisKeyword:
679-
case SyntaxKind.ImportKeyword:
680679
writeTokenNode(node);
681680
return;
682681

src/compiler/parser.ts

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,10 @@ namespace ts {
4646
}
4747
}
4848

49-
/**
50-
* Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes
51-
* stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise,
52-
* embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns
53-
* a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned.
54-
*
55-
* @param node a given node to visit its children
56-
* @param cbNode a callback to be invoked for all child nodes
57-
* @param cbNodeArray a callback to be invoked for embedded array
58-
*/
49+
// Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes
50+
// stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise,
51+
// embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns
52+
// a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned.
5953
export function forEachChild<T>(node: Node, cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
6054
if (!node) {
6155
return;
@@ -2415,7 +2409,7 @@ namespace ts {
24152409
if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) {
24162410
return parseSignatureMember(SyntaxKind.CallSignature);
24172411
}
2418-
if (token() === SyntaxKind.NewKeyword && lookAhead(nextTokenIsOpenParenOrLessThan)) {
2412+
if (token() === SyntaxKind.NewKeyword && lookAhead(isStartOfConstructSignature)) {
24192413
return parseSignatureMember(SyntaxKind.ConstructSignature);
24202414
}
24212415
const fullStart = getNodePos();
@@ -2426,7 +2420,7 @@ namespace ts {
24262420
return parsePropertyOrMethodSignature(fullStart, modifiers);
24272421
}
24282422

2429-
function nextTokenIsOpenParenOrLessThan() {
2423+
function isStartOfConstructSignature() {
24302424
nextToken();
24312425
return token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken;
24322426
}
@@ -2782,7 +2776,6 @@ namespace ts {
27822776
case SyntaxKind.SlashToken:
27832777
case SyntaxKind.SlashEqualsToken:
27842778
case SyntaxKind.Identifier:
2785-
case SyntaxKind.ImportKeyword:
27862779
return true;
27872780
default:
27882781
return isIdentifier();
@@ -3516,10 +3509,10 @@ namespace ts {
35163509
* 5) --UnaryExpression[?Yield]
35173510
*/
35183511
if (isUpdateExpression()) {
3519-
const updateExpression = parseUpdateExpression();
3512+
const incrementExpression = parseIncrementExpression();
35203513
return token() === SyntaxKind.AsteriskAsteriskToken ?
3521-
<BinaryExpression>parseBinaryExpressionRest(getBinaryOperatorPrecedence(), updateExpression) :
3522-
updateExpression;
3514+
<BinaryExpression>parseBinaryExpressionRest(getBinaryOperatorPrecedence(), incrementExpression) :
3515+
incrementExpression;
35233516
}
35243517

35253518
/**
@@ -3585,7 +3578,7 @@ namespace ts {
35853578
}
35863579
// falls through
35873580
default:
3588-
return parseUpdateExpression();
3581+
return parseIncrementExpression();
35893582
}
35903583
}
35913584

@@ -3601,7 +3594,7 @@ namespace ts {
36013594
*/
36023595
function isUpdateExpression(): boolean {
36033596
// This function is called inside parseUnaryExpression to decide
3604-
// whether to call parseSimpleUnaryExpression or call parseUpdateExpression directly
3597+
// whether to call parseSimpleUnaryExpression or call parseIncrementExpression directly
36053598
switch (token()) {
36063599
case SyntaxKind.PlusToken:
36073600
case SyntaxKind.MinusToken:
@@ -3625,17 +3618,17 @@ namespace ts {
36253618
}
36263619

36273620
/**
3628-
* Parse ES7 UpdateExpression. UpdateExpression is used instead of ES6's PostFixExpression.
3621+
* Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
36293622
*
3630-
* ES7 UpdateExpression[yield]:
3623+
* ES7 IncrementExpression[yield]:
36313624
* 1) LeftHandSideExpression[?yield]
36323625
* 2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
36333626
* 3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
36343627
* 4) ++LeftHandSideExpression[?yield]
36353628
* 5) --LeftHandSideExpression[?yield]
36363629
* In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression
36373630
*/
3638-
function parseUpdateExpression(): UpdateExpression {
3631+
function parseIncrementExpression(): IncrementExpression {
36393632
if (token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) {
36403633
const node = <PrefixUnaryExpression>createNode(SyntaxKind.PrefixUnaryExpression);
36413634
node.operator = <PrefixUnaryOperator>token();
@@ -3685,35 +3678,25 @@ namespace ts {
36853678
// CallExpression Arguments
36863679
// CallExpression[Expression]
36873680
// CallExpression.IdentifierName
3688-
// import (AssignmentExpression)
3689-
// super Arguments
3681+
// super ( ArgumentListopt )
36903682
// super.IdentifierName
36913683
//
3692-
// Because of the recursion in these calls, we need to bottom out first. There are three
3693-
// bottom out states we can run into: 1) We see 'super' which must start either of
3694-
// the last two CallExpression productions. 2) We see 'import' which must start import call.
3695-
// 3)we have a MemberExpression which either completes the LeftHandSideExpression,
3696-
// or starts the beginning of the first four CallExpression productions.
3697-
let expression: MemberExpression;
3698-
if (token() === SyntaxKind.ImportKeyword && lookAhead(nextTokenIsOpenParenOrLessThan)) {
3699-
// We don't want to eagerly consume all import keyword as import call expression so we look a head to find "("
3700-
// For example:
3701-
// var foo3 = require("subfolder
3702-
// import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression
3703-
sourceFile.flags |= NodeFlags.PossiblyContainDynamicImport;
3704-
expression = parseTokenNode<PrimaryExpression>();
3705-
}
3706-
else {
3707-
expression = token() === SyntaxKind.SuperKeyword ? parseSuperExpression() : parseMemberExpressionOrHigher();
3708-
}
3684+
// Because of the recursion in these calls, we need to bottom out first. There are two
3685+
// bottom out states we can run into. Either we see 'super' which must start either of
3686+
// the last two CallExpression productions. Or we have a MemberExpression which either
3687+
// completes the LeftHandSideExpression, or starts the beginning of the first four
3688+
// CallExpression productions.
3689+
const expression = token() === SyntaxKind.SuperKeyword
3690+
? parseSuperExpression()
3691+
: parseMemberExpressionOrHigher();
37093692

37103693
// Now, we *may* be complete. However, we might have consumed the start of a
37113694
// CallExpression. As such, we need to consume the rest of it here to be complete.
37123695
return parseCallExpressionRest(expression);
37133696
}
37143697

37153698
function parseMemberExpressionOrHigher(): MemberExpression {
3716-
// Note: to make our lives simpler, we decompose the NewExpression productions and
3699+
// Note: to make our lives simpler, we decompose the the NewExpression productions and
37173700
// place ObjectCreationExpression and FunctionExpression into PrimaryExpression.
37183701
// like so:
37193702
//
@@ -4807,11 +4790,11 @@ namespace ts {
48074790
// however, we say they are here so that we may gracefully parse them and error later.
48084791
case SyntaxKind.CatchKeyword:
48094792
case SyntaxKind.FinallyKeyword:
4810-
case SyntaxKind.ImportKeyword:
48114793
return true;
48124794

48134795
case SyntaxKind.ConstKeyword:
48144796
case SyntaxKind.ExportKeyword:
4797+
case SyntaxKind.ImportKeyword:
48154798
return isStartOfDeclaration();
48164799

48174800
case SyntaxKind.AsyncKeyword:

0 commit comments

Comments
 (0)