Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 8, 2022
1 parent 3eca0c5 commit 28ee692
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions scripts/build/modify-typescript-module.mjs
Expand Up @@ -4,7 +4,7 @@ import { outdent } from "outdent";
import MagicString from "magic-string";
import { writeFile, PROJECT_ROOT } from "../utils/index.mjs";

function* getSubmodules(text) {
function* getModules(text) {
const parts = text.split(/(?<=\n)( {2}\/\/ src\/\S+\n)/);

let start = parts[0].length;
Expand Down Expand Up @@ -36,7 +36,7 @@ class TypeScriptModuleSource {

constructor(text) {
this.#source = new MagicString(text);
this.modules = [...getSubmodules(text)];
this.modules = [...getModules(text)];
}

replaceModule(module, replacement) {
Expand All @@ -56,20 +56,6 @@ class TypeScriptModuleSource {
return this.replaceModule(module, "");
}

removeSubmodule(testFunction) {
return this.replaceSubmodule(testFunction, "");
}

replaceSubmodules(testFunction, replacement = "") {
const modules = this.modules.filter((module) => testFunction(module));

for (const { start, end } of modules) {
this.#source.overwrite(start, end, replacement);
}

return this;
}

replaceAlignedCode({ start, end, replacement = "" }) {
const regexp = new RegExp(
[
Expand Down Expand Up @@ -117,7 +103,7 @@ class TypeScriptModuleSource {
applyChanges() {
const text = this.#source.toString();
this.#source = new MagicString(text);
this.modules = getSubmodules(text);
this.modules = getModules(text);
}

toString() {
Expand Down Expand Up @@ -227,10 +213,10 @@ function modifyTypescriptModule(text) {
// performanceCore
source.replaceModule(
"src/compiler/performanceCore.ts",
outdent`
var tryGetNativePerformanceHooks = () => {};
var timestamp = Date.now;
`
var tryGetNativePerformanceHooks = () => {};
var timestamp = Date.now;
`
);


Expand All @@ -240,9 +226,9 @@ function modifyTypescriptModule(text) {
source.removeModule("src/compiler/factory/emitHelpers.ts");
source.replaceModule(
"src/compiler/factory/nodeConverters.ts",
outdent`
var createNodeConverters = () => new Proxy({}, {get: () => () => {}});
`
var createNodeConverters = () => new Proxy({}, {get: () => () => {}})
`
);

/* spell-checker: disable */
Expand Down

0 comments on commit 28ee692

Please sign in to comment.