Skip to content

Commit cd3e530

Browse files
authored
Reduce size of parser-typescript.js (#13431)
1 parent 371c709 commit cd3e530

2 files changed

Lines changed: 486 additions & 55 deletions

File tree

scripts/build/config.mjs

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "node:path";
22
import { createRequire } from "node:module";
33
import createEsmUtils from "esm-utils";
44
import { PROJECT_ROOT } from "../utils/index.mjs";
5+
import modifyTypescriptModule from "./modify-typescript-module.mjs";
56

67
const { require } = createEsmUtils(import.meta);
78

@@ -101,62 +102,8 @@ const parsers = [
101102
},
102103
{
103104
module: require.resolve("typescript"),
104-
process(text) {
105-
return text.replace(
106-
/(?<=\n)(?<indentString>\s+)function tryGetNodePerformanceHooks\(\) {.*?\n\k<indentString>}(?=\n)/s,
107-
"function tryGetNodePerformanceHooks() {}"
108-
);
109-
},
105+
process: modifyTypescriptModule,
110106
},
111-
112-
...Object.entries({
113-
// `typescript/lib/typescript.js` expose extra global objects
114-
// `TypeScript`, `toolsVersion`, `globalThis`
115-
'typeof process === "undefined" || process.browser': "false",
116-
'typeof globalThis === "object"': "true",
117-
118-
"_fs.realpathSync.native":
119-
"_fs.realpathSync && _fs.realpathSync.native",
120-
// Remove useless `ts.sys`
121-
"ts.sys = ": "ts.sys = undefined && ",
122-
123-
// Remove useless language service
124-
"ts.realizeDiagnostics = ": "ts.realizeDiagnostics = undefined && ",
125-
"ts.TypeScriptServicesFactory = ":
126-
"ts.TypeScriptServicesFactory = undefined && ",
127-
"var ShimBase = ": "var ShimBase = undefined && ",
128-
"var TypeScriptServicesFactory = ":
129-
"var TypeScriptServicesFactory = undefined && ",
130-
"var LanguageServiceShimObject = ":
131-
"var LanguageServiceShimObject = undefined && ",
132-
"var CoreServicesShimHostAdapter = ":
133-
"var CoreServicesShimHostAdapter = undefined && ",
134-
"var LanguageServiceShimHostAdapter = ":
135-
"var LanguageServiceShimHostAdapter = undefined && ",
136-
"var ScriptSnapshotShimAdapter = ":
137-
"var ScriptSnapshotShimAdapter = undefined && ",
138-
"var ClassifierShimObject = ":
139-
"var ClassifierShimObject = undefined && ",
140-
"var CoreServicesShimObject = ":
141-
"var CoreServicesShimObject = undefined && ",
142-
"function simpleForwardCall(": "0 && function simpleForwardCall(",
143-
"function forwardJSONCall(": "0 && function forwardJSONCall(",
144-
"function forwardCall(": "0 && function forwardCall(",
145-
"function realizeDiagnostics(": "0 && function realizeDiagnostics(",
146-
"function realizeDiagnostic(": "0 && function realizeDiagnostic(",
147-
"function convertClassifications(":
148-
"0 && function convertClassifications(",
149-
150-
// Dynamic `require()`s
151-
"ts.sys && ts.sys.require": "false",
152-
"require(etwModulePath)": "undefined",
153-
'require("source-map-support").install()': "",
154-
"require(modulePath)": "undefined",
155-
}).map(([find, replacement]) => ({
156-
module: require.resolve("typescript"),
157-
find,
158-
replacement,
159-
})),
160107
{
161108
module: require.resolve("debug/src/browser.js"),
162109
path: require.resolve("./shims/debug.cjs"),

0 commit comments

Comments
 (0)