Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove legacy node syntax polyfills #260

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,5 +1,5 @@
import { destr } from "destr";
import { lt } from "semver";

Check warning on line 2 in src/options.ts

View workflow job for this annotation

GitHub Actions / autofix

'lt' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 2 in src/options.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 20)

'lt' is defined but never used. Allowed unused vars must match /^_/u
import objectHash from "object-hash";

import type { JITIOptions } from "./types";
Expand All @@ -20,7 +20,6 @@
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 @@
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