mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
module: add module.stripTypeScriptTypes
PR-URL: https://github.com/nodejs/node/pull/55282 Fixes: https://github.com/nodejs/node/issues/54300 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
This commit is contained in:
parent
cbb72ebfa7
commit
53b1050e6f
10 changed files with 358 additions and 88 deletions
|
@ -151,8 +151,8 @@ const {
|
|||
setHasStartedUserCJSExecution,
|
||||
stripBOM,
|
||||
toRealPath,
|
||||
stripTypeScriptTypes,
|
||||
} = require('internal/modules/helpers');
|
||||
const { stripTypeScriptModuleTypes } = require('internal/modules/typescript');
|
||||
const packageJsonReader = require('internal/modules/package_json_reader');
|
||||
const { getOptionValue, getEmbedderOptions } = require('internal/options');
|
||||
const shouldReportRequiredModules = getLazy(() => process.env.WATCH_REPORT_DEPENDENCIES);
|
||||
|
@ -1357,7 +1357,7 @@ let hasPausedEntry = false;
|
|||
function loadESMFromCJS(mod, filename) {
|
||||
let source = getMaybeCachedSource(mod, filename);
|
||||
if (getOptionValue('--experimental-strip-types') && path.extname(filename) === '.mts') {
|
||||
source = stripTypeScriptTypes(source, filename);
|
||||
source = stripTypeScriptModuleTypes(source, filename);
|
||||
}
|
||||
const cascadedLoader = require('internal/modules/esm/loader').getOrInitializeCascadedLoader();
|
||||
const isMain = mod[kIsMainSymbol];
|
||||
|
@ -1599,7 +1599,7 @@ function getMaybeCachedSource(mod, filename) {
|
|||
|
||||
function loadCTS(module, filename) {
|
||||
const source = getMaybeCachedSource(module, filename);
|
||||
const code = stripTypeScriptTypes(source, filename);
|
||||
const code = stripTypeScriptModuleTypes(source, filename);
|
||||
module._compile(code, filename, 'commonjs');
|
||||
}
|
||||
|
||||
|
@ -1611,7 +1611,7 @@ function loadCTS(module, filename) {
|
|||
function loadTS(module, filename) {
|
||||
// If already analyzed the source, then it will be cached.
|
||||
const source = getMaybeCachedSource(module, filename);
|
||||
const content = stripTypeScriptTypes(source, filename);
|
||||
const content = stripTypeScriptModuleTypes(source, filename);
|
||||
let format;
|
||||
const pkg = packageJsonReader.getNearestParentPackageJSON(filename);
|
||||
// Function require shouldn't be used in ES modules.
|
||||
|
@ -1631,7 +1631,7 @@ function loadTS(module, filename) {
|
|||
if (Module._cache[parentPath]) {
|
||||
let parentSource;
|
||||
try {
|
||||
parentSource = stripTypeScriptTypes(fs.readFileSync(parentPath, 'utf8'), parentPath);
|
||||
parentSource = stripTypeScriptModuleTypes(fs.readFileSync(parentPath, 'utf8'), parentPath);
|
||||
} catch {
|
||||
// Continue regardless of error.
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue