Skip to content

Commit

Permalink
refactor: remove legacy node syntax polyfills
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 27, 2024
1 parent 420f1fb commit bc38883
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 77 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
"@babel/plugin-syntax-class-properties": "^7.12.13",
"@babel/plugin-syntax-import-assertions": "^7.24.7",
"@babel/plugin-transform-export-namespace-from": "^7.24.7",
"@babel/plugin-transform-nullish-coalescing-operator": "^7.24.7",
"@babel/plugin-transform-optional-chaining": "^7.24.7",
"@babel/plugin-transform-typescript": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@babel/template": "^7.24.7",
Expand Down
53 changes: 0 additions & 53 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions src/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ export default function transform(opts: TransformOptions): TRANSFORM_RESULT {
_opts.plugins.push(require("@babel/plugin-syntax-import-assertions"));
}

if (opts.legacy) {
_opts.plugins.push(
require("@babel/plugin-transform-nullish-coalescing-operator"),
);
_opts.plugins.push(require("@babel/plugin-transform-optional-chaining"));
}

if (opts.babel && Array.isArray(opts.babel.plugins)) {
_opts.plugins?.push(...opts.babel.plugins);
}
Expand Down
5 changes: 1 addition & 4 deletions src/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { dirname, basename, extname } from "pathe";
import { hasESMSyntax } from "mlly";
import {
debug,
detectLegacySyntax,
jitiInteropDefault,
readNearestPackageJSON,
wrapModule,
Expand Down Expand Up @@ -43,9 +42,7 @@ export function evalModule(
(isTypescript ||
isESM ||
ctx.isTransformRe.test(filename) ||
hasESMSyntax(source) ||
(ctx.opts.legacy && detectLegacySyntax(source)));

hasESMSyntax(source));
const start = performance.now();
if (needsTranspile) {
source = transform(ctx, {
Expand Down
4 changes: 0 additions & 4 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const jitiDefaults: JITIOptions = {
sourceMaps: _EnvSourceMaps === undefined ? false : !!_EnvSourceMaps,
interopDefault: false,
cacheVersion: "7",
legacy: lt(process.version || "0.0.0", "14.0.0"),
extensions: [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts", ".json"],
alias: _EnvAlias,
nativeModules: _EnvNative || [],
Expand All @@ -32,9 +31,6 @@ export function resolveJitiOptions(userOptions: JITIOptions): JITIOptions {
const opts: JITIOptions = { ...jitiDefaults, ...userOptions };

// Cache dependencies
if (opts.legacy) {
opts.cacheVersion += "-legacy";
}
if (opts.transformOptions) {
opts.cacheVersion += "-" + objectHash(opts.transformOptions);
}
Expand Down
1 change: 0 additions & 1 deletion src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { debug } from "./utils";
export function transform(ctx: Context, topts: any): string {
let code = getCache(ctx, topts.filename, topts.source, () => {
const res = ctx.opts.transform!({
legacy: ctx.opts.legacy,
...ctx.opts.transformOptions,
babel: {
...(ctx.opts.sourceMaps
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export type TransformOptions = {
filename?: string;
ts?: boolean;
retainLines?: boolean;
legacy?: boolean;
async?: boolean;
[key: string]: any;
};
Expand All @@ -60,7 +59,6 @@ export type JITIOptions = {
v8cache?: boolean;
interopDefault?: boolean;
cacheVersion?: string;
legacy?: boolean;
extensions?: string[];
transformOptions?: Omit<TransformOptions, "source">;
alias?: Record<string, string>;
Expand Down
4 changes: 0 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export function md5(content: string, len = 8) {
return createHash("md5").update(content).digest("hex").slice(0, len);
}

export function detectLegacySyntax(code: string) {
return code.match(/\?\.|\?\?/);
}

export function isObject(val: any) {
return val !== null && typeof val === "object";
}
Expand Down

0 comments on commit bc38883

Please sign in to comment.