mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #16370 from Microsoft/release-2.4_manuallyPortTheFlagToIncrementalSourceFile
[Release 2.4] Manually port the flag to incremental source file
This commit is contained in:
@@ -481,7 +481,11 @@ namespace ts {
|
||||
// becoming detached from any SourceFile). It is recommended that this SourceFile not
|
||||
// be used once 'update' is called on it.
|
||||
export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile {
|
||||
return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
|
||||
const newSourceFile = IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
|
||||
// Because new source file node is created, it may not have the flag PossiblyContainDynamicImport. This is the case if there is no new edit to add dynamic import.
|
||||
// We will manually port the flag to the new source file.
|
||||
newSourceFile.flags |= (sourceFile.flags & NodeFlags.PossiblyContainDynamicImport);
|
||||
return newSourceFile;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
||||
@@ -514,14 +514,14 @@ namespace ts {
|
||||
|
||||
function visitImportCallExpression(node: ImportCall): Expression {
|
||||
switch (compilerOptions.module) {
|
||||
case ModuleKind.CommonJS:
|
||||
return transformImportCallExpressionCommonJS(node);
|
||||
case ModuleKind.AMD:
|
||||
return transformImportCallExpressionAMD(node);
|
||||
case ModuleKind.UMD:
|
||||
return transformImportCallExpressionUMD(node);
|
||||
case ModuleKind.CommonJS:
|
||||
default:
|
||||
return transformImportCallExpressionCommonJS(node);
|
||||
}
|
||||
Debug.fail("All supported module kind in this transformation step should have been handled");
|
||||
}
|
||||
|
||||
function transformImportCallExpressionUMD(node: ImportCall): Expression {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
error TS2468: Cannot find global value 'Promise'.
|
||||
tests/cases/conformance/dynamicImport/2.ts(3,24): error TS2712: 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.
|
||||
tests/cases/conformance/dynamicImport/2.ts(7,12): error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.
|
||||
tests/cases/conformance/dynamicImport/2.ts(9,29): error TS2712: 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.
|
||||
|
||||
|
||||
!!! error TS2468: Cannot find global value 'Promise'.
|
||||
==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ====
|
||||
export class B {
|
||||
print() { return "I am B"}
|
||||
}
|
||||
|
||||
export function foo() { return "foo" }
|
||||
|
||||
==== tests/cases/conformance/dynamicImport/1.ts (0 errors) ====
|
||||
export function backup() { return "backup"; }
|
||||
|
||||
==== tests/cases/conformance/dynamicImport/2.ts (3 errors) ====
|
||||
declare var console: any;
|
||||
class C {
|
||||
private myModule = import("./0");
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2712: 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.
|
||||
method() {
|
||||
this.myModule.then(Zero => {
|
||||
console.log(Zero.foo());
|
||||
}, async err => {
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.
|
||||
console.log(err);
|
||||
let one = await import("./1");
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2712: 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.
|
||||
console.log(one.backup());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
//// [tests/cases/conformance/dynamicImport/importCallExpressionNoModuleKindSpecified.ts] ////
|
||||
|
||||
//// [0.ts]
|
||||
export class B {
|
||||
print() { return "I am B"}
|
||||
}
|
||||
|
||||
export function foo() { return "foo" }
|
||||
|
||||
//// [1.ts]
|
||||
export function backup() { return "backup"; }
|
||||
|
||||
//// [2.ts]
|
||||
declare var console: any;
|
||||
class C {
|
||||
private myModule = import("./0");
|
||||
method() {
|
||||
this.myModule.then(Zero => {
|
||||
console.log(Zero.foo());
|
||||
}, async err => {
|
||||
console.log(err);
|
||||
let one = await import("./1");
|
||||
console.log(one.backup());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//// [0.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var B = (function () {
|
||||
function B() {
|
||||
}
|
||||
B.prototype.print = function () { return "I am B"; };
|
||||
return B;
|
||||
}());
|
||||
exports.B = B;
|
||||
function foo() { return "foo"; }
|
||||
exports.foo = foo;
|
||||
//// [1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
function backup() { return "backup"; }
|
||||
exports.backup = backup;
|
||||
//// [2.js]
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var C = (function () {
|
||||
function C() {
|
||||
this.myModule = Promise.resolve().then(function () { return require("./0"); });
|
||||
}
|
||||
C.prototype.method = function () {
|
||||
var _this = this;
|
||||
this.myModule.then(function (Zero) {
|
||||
console.log(Zero.foo());
|
||||
}, function (err) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var one;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
console.log(err);
|
||||
return [4 /*yield*/, Promise.resolve().then(function () { return require("./1"); })];
|
||||
case 1:
|
||||
one = _a.sent();
|
||||
console.log(one.backup());
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
};
|
||||
return C;
|
||||
}());
|
||||
@@ -0,0 +1,24 @@
|
||||
// @filename: 0.ts
|
||||
export class B {
|
||||
print() { return "I am B"}
|
||||
}
|
||||
|
||||
export function foo() { return "foo" }
|
||||
|
||||
// @filename: 1.ts
|
||||
export function backup() { return "backup"; }
|
||||
|
||||
// @filename: 2.ts
|
||||
declare var console: any;
|
||||
class C {
|
||||
private myModule = import("./0");
|
||||
method() {
|
||||
this.myModule.then(Zero => {
|
||||
console.log(Zero.foo());
|
||||
}, async err => {
|
||||
console.log(err);
|
||||
let one = await import("./1");
|
||||
console.log(one.backup());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
// @lib: es6
|
||||
|
||||
// @Filename: ./foo.ts
|
||||
//// export function bar() { return 1; }
|
||||
|
||||
//// var x1 = import("./foo");
|
||||
//// x1.then(foo => {
|
||||
//// var s: string = foo.bar();
|
||||
//// })
|
||||
//// /*1*/
|
||||
|
||||
verify.numberOfErrorsInCurrentFile(1);
|
||||
goTo.marker("1");
|
||||
edit.insert(" ");
|
||||
verify.numberOfErrorsInCurrentFile(1);
|
||||
Reference in New Issue
Block a user