Skip to content
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
158 changes: 40 additions & 118 deletions bun.lock

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rolldown-plugin/solid",
"version": "0.0.1",
"version": "0.0.2",
"description": "A Rolldown plugin for compiling SolidJS JSX/TSX files",
"license": "MIT",
"author": "gameroman",
Expand Down Expand Up @@ -30,19 +30,18 @@
"prepublishOnly": "bun run build"
},
"dependencies": {
"@babel/helper-plugin-utils": "^7.28.6",
"@babel/helper-validator-option": "^7.27.1",
"@babel/core": "^7.28.6",
"@babel/helper-module-imports": "7.28.6",
"@babel/template": "7.28.6",
"@babel/traverse": "7.29.0",
"@babel/types": "7.29.0",
"@babel/helper-plugin-utils": "^8.0.0-rc.1",
"@babel/helper-validator-option": "^8.0.0-rc.1",
"@babel/core": "^8.0.0-rc.1",
"@babel/helper-module-imports": "^8.0.0-rc.1",
"@babel/template": "^8.0.0-rc.1",
"@babel/traverse": "^8.0.0-rc.1",
"@babel/types": "^8.0.0-rc.1",
"html-entities": "2.6.0",
"parse5": "^8.0.0"
},
"devDependencies": {
"@biomejs/biome": "2.4.0",
"@types/babel__core": "^7.20.5",
"@types/bun": "^1.3.9",
"@types/node": "^25.2.3",
"solid-js": "1.9.11",
Expand All @@ -56,5 +55,16 @@
},
"engines": {
"node": ">=20.0.0"
},
"overrides": {
"@babel/helper-plugin-utils": "8.0.0-rc.1",
"@babel/helper-validator-identifier": "8.0.0-rc.1",
"@babel/helper-validator-option": "8.0.0-rc.1",
"@babel/code-frame": "8.0.0-rc.1",
"@babel/core": "8.0.0-rc.1",
"@babel/helper-module-imports": "8.0.0-rc.1",
"@babel/template": "8.0.0-rc.1",
"@babel/traverse": "8.0.0-rc.1",
"@babel/types": "8.0.0-rc.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-expect-error: Babel types are not installed
import { declare } from "@babel/helper-plugin-utils";
import type { Visitor } from "@babel/traverse";
import postprocess from "./shared/postprocess";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as parse5 from "parse5";
/** `bodyElement` will be used as a `context` (The place where we run `innerHTML`) */
const bodyElement = parse5.parse(
`<!DOCTYPE html><html><head></head><body></body></html>`,
// @ts-ignore
// @ts-expect-error
).childNodes[1]!.childNodes[1];

function innerHTML(htmlFragment: string) {
Expand All @@ -23,7 +23,13 @@ function innerHTML(htmlFragment: string) {
* browser: string; // what the browser returned from evaluating `html`
* } | null}
*/
export function isInvalidMarkup(html: string) {
export function isInvalidMarkup(html: string):
| {
html: string; // html stripped of attributives and content
browser: string; // what the browser returned from evaluating `html`
}
| null
| undefined {
html = html

// normalize dom-expressions comments, so comments location are also validated
Expand Down
2 changes: 1 addition & 1 deletion src/plugin-transform-typescript/const-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function transpileConstEnum(
);
} else {
path.replaceWith(
t.variableDeclaration(undefined ? "const" : "var", [
t.variableDeclaration("const", [
t.variableDeclarator(path.node.id, obj),
]),
);
Expand Down
20 changes: 7 additions & 13 deletions src/plugin-transform-typescript/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,9 @@ const buildEnumMember = (isString: boolean, options: Record<string, unknown>) =>
*/
function enumFill(path: NodePath<t.TSEnumDeclaration>, t: t, id: t.Identifier) {
const { enumValues, data, isPure } = translateEnumValues(path, t);
const enumMembers: NodePath<t.TSEnumMember>[] = undefined
? // @ts-ignore(Babel 7 vs Babel 8) Babel 8 AST
path
.get("body")
.get("members")
: path.get("members");
const enumMembers: NodePath<t.TSEnumMember>[] = path
.get("body")
.get("members");
const assignments = [];
for (let i = 0; i < enumMembers.length; i++) {
const [memberName, memberValue] = enumValues[i];
Expand All @@ -185,7 +182,7 @@ function enumFill(path: NodePath<t.TSEnumDeclaration>, t: t, id: t.Identifier) {
}

function isSyntacticallyString(expr: t.Expression): boolean {
// @ts-ignore(Babel 7 vs Babel 8) Type 'Expression | Super' is not assignable to type 'Expression' in Babel 8
// @ts-expect-error(Babel 7 vs Babel 8) Type 'Expression | Super' is not assignable to type 'Expression' in Babel 8
expr = skipTransparentExprWrapperNodes(expr);
switch (expr.type) {
case "BinaryExpression": {
Expand Down Expand Up @@ -268,12 +265,9 @@ export function translateEnumValues(path: NodePath<t.TSEnumDeclaration>, t: t) {
let lastName: string;
let isPure = true;

const enumMembers: NodePath<t.TSEnumMember>[] = undefined
? // @ts-ignore(Babel 7 vs Babel 8) Babel 8 AST
path
.get("body")
.get("members")
: path.get("members");
const enumMembers: NodePath<t.TSEnumMember>[] = path
.get("body")
.get("members");

const enumValues: [name: string, value: t.Expression][] = enumMembers.map(
(memberPath) => {
Expand Down
90 changes: 19 additions & 71 deletions src/plugin-transform-typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { PluginPass } from "@babel/core";
// @ts-expect-error: Babel types are not installed
import { declare } from "@babel/helper-plugin-utils";
import type { Binding, NodePath } from "@babel/traverse";
import * as t from "@babel/types";
Expand All @@ -15,8 +14,8 @@ import syntaxTypeScript from "./plugin-syntax-typescript";
function isInType(path: NodePath) {
switch (path.parent.type) {
case "TSTypeReference":
case "TSExpressionWithTypeArguments":
case "TSExpressionWithTypeArguments":
case "TSClassImplements":
case "TSInterfaceHeritage":
case "TSTypeQuery":
return true;
case "TSQualifiedName":
Expand Down Expand Up @@ -110,11 +109,6 @@ const pluginTransformTypescript = declare((api, opts: Options) => {
optimizeConstEnums = false,
} = opts;

if (true) {
// eslint-disable-next-line no-var
var { allowDeclareFields = false } = opts;
}

const classMemberVisitors = {
field(
path: NodePath<
Expand All @@ -124,14 +118,6 @@ const pluginTransformTypescript = declare((api, opts: Options) => {
) {
const { node } = path;

if (true) {
if (!allowDeclareFields && node.declare) {
throw path.buildCodeFrameError(
`The 'declare' modifier is only allowed when the 'allowDeclareFields' option of ` +
`@babel/plugin-transform-typescript or @babel/preset-typescript is enabled.`,
);
}
}
if (node.declare) {
if (node.value) {
throw path.buildCodeFrameError(
Expand All @@ -147,28 +133,8 @@ const pluginTransformTypescript = declare((api, opts: Options) => {
`Definitely assigned fields cannot be initialized here, but only in the constructor`,
);
}
if (true) {
// keep the definitely assigned fields only when `allowDeclareFields` (equivalent of
// Typescript's `useDefineForClassFields`) is true
if (
!allowDeclareFields &&
!node.decorators &&
!t.isClassPrivateProperty(node)
) {
path.remove();
}
}
} else if (node.abstract) {
path.remove();
} else if (true) {
if (
!allowDeclareFields &&
!node.value &&
!node.decorators &&
!t.isClassPrivateProperty(node)
) {
path.remove();
}
}

if (node.accessibility) node.accessibility = null;
Expand Down Expand Up @@ -367,9 +333,6 @@ const pluginTransformTypescript = declare((api, opts: Options) => {
const binding = stmt.scope.getBinding(id.name);
if (
binding &&
(undefined ||
// @ts-ignore(Babel 7 vs Babel 8) Babel 7 AST
!stmt.node.isExport) &&
isImportTypeOnly({
binding,
programPath: path,
Expand Down Expand Up @@ -429,7 +392,7 @@ const pluginTransformTypescript = declare((api, opts: Options) => {
return;
}

if (undefined && t.isTSImportEqualsDeclaration(path.node.declaration)) {
if (t.isTSImportEqualsDeclaration(path.node.declaration)) {
return;
}

Expand Down Expand Up @@ -562,7 +525,7 @@ const pluginTransformTypescript = declare((api, opts: Options) => {

if (node.typeParameters) node.typeParameters = null;

if (node.superTypeParameters) node.superTypeParameters = null;
if (node.superTypeArguments) node.superTypeArguments = null;

if (node.implements) node.implements = null;
if (node.abstract) node.abstract = null;
Expand Down Expand Up @@ -655,7 +618,7 @@ const pluginTransformTypescript = declare((api, opts: Options) => {

{
path.replaceWith(
// @ts-ignore(Babel 7 vs Babel 8) Babel 7 AST
// @ts-expect-error(Babel 7 vs Babel 8) Babel 7 AST
path.node.isExport ? t.exportNamedDeclaration(newNode) : newNode,
);
}
Expand All @@ -678,69 +641,54 @@ const pluginTransformTypescript = declare((api, opts: Options) => {
path.replaceWith(path.node.expression);
},

[`TSAsExpression${
// Added in Babel 7.20.0
t.tsSatisfiesExpression ? "|TSSatisfiesExpression" : ""
}`](path: NodePath<t.TSAsExpression | t.TSSatisfiesExpression>) {
["TSAsExpression|TSSatisfiesExpression"](
path: NodePath<t.TSAsExpression | t.TSSatisfiesExpression>,
) {
let { node }: { node: t.Expression } = path;
do {
node = node.expression;
} while (t.isTSAsExpression(node) || t.isTSSatisfiesExpression?.(node));
path.replaceWith(node);
},

[undefined
? "TSNonNullExpression|TSInstantiationExpression"
: /* This has been introduced in Babel 7.18.0
We use api.types.* and not t.* for feature detection,
because the Babel version that is running this plugin
(where we check if the visitor is valid) might be different
from the Babel version that we resolve with `import "@babel/core"`.
This happens, for example, with Next.js that bundled `@babel/core`
but allows loading unbundled plugin (which cannot obviously import
the bundled `@babel/core` version).
*/

api.types.tsInstantiationExpression
? "TSNonNullExpression|TSInstantiationExpression"
: "TSNonNullExpression"](
["TSNonNullExpression|TSInstantiationExpression"](
path: NodePath<t.TSNonNullExpression | t.TSInstantiationExpression>,
) {
path.replaceWith(path.node.expression);
},

CallExpression(path) {
{
// @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8
path.node.typeParameters = null;
// @ts-expect-error(Babel 7 vs Babel 8) Removed in Babel 8
path.node.typeArguments = null;
}
},

OptionalCallExpression(path) {
{
// @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8
path.node.typeParameters = null;
// @ts-expect-error(Babel 7 vs Babel 8) Removed in Babel 8
path.node.typeArguments = null;
}
},

NewExpression(path) {
{
// @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8
path.node.typeParameters = null;
// @ts-expect-error(Babel 7 vs Babel 8) Removed in Babel 8
path.node.typeArguments = null;
}
},

JSXOpeningElement(path) {
{
// @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8
path.node.typeParameters = null;
// @ts-expect-error(Babel 7 vs Babel 8) Removed in Babel 8
path.node.typeArguments = null;
}
},

TaggedTemplateExpression(path) {
{
// @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8
path.node.typeParameters = null;
// @ts-expect-error(Babel 7 vs Babel 8) Removed in Babel 8
path.node.typeArguments = null;
}
},
},
Expand Down
3 changes: 0 additions & 3 deletions src/plugin-transform-typescript/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export function getFirstIdentifier(node: t.TSEntityName): t.Identifier {
}
// In Babel 8 TSEntityName also includes ThisExpression, however, a namespace
// id must not be a ThisExpression or a TSQualifiedName { left: ThisExpression }.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
return getFirstIdentifier((node as t.TSQualifiedName).left);
}

Expand Down Expand Up @@ -105,7 +104,6 @@ function handleVariableDeclaration(
const bindingIdentifiers = t.getBindingIdentifiers(node);
const assignments = [];
// getBindingIdentifiers returns an object without prototype.
// eslint-disable-next-line guard-for-in
for (const idName in bindingIdentifiers) {
assignments.push(
t.assignmentExpression(
Expand Down Expand Up @@ -191,7 +189,6 @@ function handleNested(
case "VariableDeclaration": {
isEmpty = false;
// getBindingIdentifiers returns an object without prototype.
// eslint-disable-next-line guard-for-in
for (const name in t.getBindingIdentifiers(subNode)) {
names.add(name);
}
Expand Down
8 changes: 1 addition & 7 deletions src/plugin-transform-typescript/plugin-syntax-typescript.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { declare } from "@babel/helper-plugin-utils";

// eslint-disable-next-line no-var
var removePlugin = function (plugins: any[], name: string) {
const removePlugin = function (plugins: any[], name: string) {
const indices: number[] = [];
plugins.forEach((plugin, i) => {
const n = Array.isArray(plugin) ? plugin[0] : plugin;
Expand Down Expand Up @@ -41,11 +40,6 @@ const syntaxTypeScript = declare((api, opts: Options) => {
// in TS depends on the extensions, and is purely dependent on 'isTSX'.
removePlugin(plugins, "jsx");

// These are now enabled by default in @babel/parser, but we push
// them for compat with older versions.
// @ts-ignore(Babel 7 vs Babel 8) These plugins have been removed
plugins.push("objectRestSpread", "classProperties");

if (isTSX) {
plugins.push("jsx");
}
Expand Down
4 changes: 1 addition & 3 deletions src/preset-typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { PluginItem } from "@babel/core";
// @ts-expect-error: Babel types are not installed
import { declarePreset } from "@babel/helper-plugin-utils";
import transformTypeScript from "../plugin-transform-typescript";
import type { Options } from "./normalize-options";
Expand All @@ -10,7 +9,6 @@ export type { Options as PresetTypescriptOptions };

const presetTypescript: unknown = declarePreset((api, opts: Options) => {
const {
allExtensions,
ignoreExtensions,
allowNamespaces,
disallowAmbiguousJSXLike,
Expand Down Expand Up @@ -41,7 +39,7 @@ const presetTypescript: unknown = declarePreset((api, opts: Options) => {
];
};

const disableExtensionDetect = allExtensions || ignoreExtensions;
const disableExtensionDetect = ignoreExtensions;

return {
plugins: rewriteImportExtensions ? [pluginRewriteTSImports] : [],
Expand Down
Loading