rolldown-plugin-access-privates 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -8
- package/src/index.ts +7 -5
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;AAE8F;;;;;;;iBAmBtE,cAAA;EACtB,OAAA;EACA,YAAA;EACA,MAAA;EACA;AAAA;EAQgH;;;;;;EAAhH,OAAA,uDAA8D,EAAA,UAAY,OAAA,EAAS,MAAA,CAAO,mBAAA,GAAsB,MAAA,CAAO,QAAA,GAAW,MAAA,CAAO,KAAA;EAuB5H;;;;;;EAhBb,YAAA,2DAAuE,EAAA,UAAY,OAAA,EAAS,MAAA,CAAO,gBAAA,GAAmB,MAAA,CAAO,kBAAA;EAf7H;;;;;;EAsBA,MAAA,cAAoB,IAAA;EAdmG;;;;;;;EAsBvH,QAAA,GAAW,UAAA;AAAA,IACJ,MAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -55,7 +55,7 @@ function AccessPrivates({ exports = true, classMembers = true, suffix = "Private
|
|
|
55
55
|
...canNotExport ? { code: "#" } : {}
|
|
56
56
|
},
|
|
57
57
|
handler: withMagicString(function(code, id, meta) {
|
|
58
|
-
let ast = meta
|
|
58
|
+
let ast = meta?.ast !== void 0 ? meta.ast : this.parse(code.original, { lang: id.endsWith(".tsx") ? "tsx" : id.endsWith(".ts") ? "ts" : id.endsWith(".jsx") ? "jsx" : "js" });
|
|
59
59
|
const visitors = {};
|
|
60
60
|
if (!canNotExport) visitors.Program = function(node) {
|
|
61
61
|
for (const child of node.body) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { type HookFilter, type Plugin } from \"rolldown\";\nimport { withMagicString } from \"rolldown-string\";\nimport { Visitor, type ESTree, type VisitorObject } from \"rolldown/utils\";\n\n/** Map exports types to their corresponding AST node types. */\nconst exportsToType = {\n variable: \"VariableDeclaration\",\n function: \"FunctionDeclaration\",\n class: \"ClassDeclaration\",\n} as const;\n\n/**\n * A Vite plugin to generate accessors for private fields to allow testing them.\n * This plugin will generate getter and setter methods for private fields and methods, allowing you to access them in your tests.\n * For example, if you have a private field `#foo`, the plugin will generate `fooPrivate` getter and setter.\n * Also automatically exports all top-level variables, functions, and classes in the module, allowing you to import them in your tests without needing to use `export` in your source code.\n *\n * @param options - Options for the plugin.\n * @returns\n */\nexport default function AccessPrivates({\n exports = true,\n classMembers = true,\n suffix = \"Private\",\n idFilter = /\\.[jt]sx?$/,\n}: {\n /**\n * Whether to export all top-level variables, functions, and classes in the module.\n * Can be an array of \"variable\", \"function\", and \"class\", or a function that will be called with the module ID and AST node of each variable, function, or class declaration.\n *\n * @default true\n */\n exports?: (\"variable\" | \"function\" | \"class\")[] | boolean | ((id: string, astNode: ESTree.VariableDeclaration | ESTree.Function | ESTree.Class) => boolean) | undefined;\n /**\n * Which class members to generate accessors for.\n * Can be an array of \"method\", \"get\", \"set\", and \"property\", or a function that will be called with the module ID and AST node of each method or property definition.\n *\n * @default true\n */\n classMembers?: (\"method\" | \"get\" | \"set\" | \"property\")[] | boolean | ((id: string, astNode: ESTree.MethodDefinition | ESTree.PropertyDefinition) => boolean) | undefined;\n /**\n * The suffix to use for the generated accessors.\n * For example, if you have a private field `#foo`, the plugin will generate `fooPrivate` getter and setter.\n *\n * @default \"Private\"\n */\n suffix?: string | ((name: string) => string) | undefined;\n /**\n * Filter for which modules the plugin should apply.\n * Can be a string, a RegExp, an array of strings and RegExps, or an object with an `include` and `exclude` property, each of which can be a string, a RegExp, or an array of strings and RegExps.\n * The filter will be applied to the module ID.\n *\n * @default /\\.[jt]sx?$/\n */\n idFilter?: HookFilter[\"id\"] | undefined;\n} = {}): Plugin {\n // Calculate which code path can be optimized.\n const canNotExport = exports === false || (Array.isArray(exports) && exports.length === 0);\n const canNotPropertyDefinition = classMembers === false || (Array.isArray(classMembers) && (classMembers.length === 0 || !classMembers.includes(\"property\")));\n const canNotMethodDefinition = classMembers === false || (Array.isArray(classMembers) && (classMembers.length === 0 || !classMembers.some((m) => m === \"method\" || m === \"get\" || m === \"set\")));\n // Transform filters in to a unified format\n if (typeof exports === \"boolean\") {\n const shouldExport = exports;\n exports = () => shouldExport;\n } else if (Array.isArray(exports)) {\n const mappedExports: ESTree.Node[\"type\"][] = exports.map((e) => exportsToType[e]);\n exports = (_id, astNode) => mappedExports.includes(astNode.type);\n }\n if (typeof classMembers === \"boolean\") {\n const shouldGenerate = classMembers;\n classMembers = () => shouldGenerate;\n } else if (Array.isArray(classMembers)) {\n const members = classMembers;\n classMembers = (_id, astNode) => {\n if (astNode.type === \"PropertyDefinition\") return members.includes(\"property\");\n if (astNode.type === \"MethodDefinition\") {\n if (astNode.kind === \"method\") return members.includes(\"method\");\n if (astNode.kind === \"get\") return members.includes(\"get\");\n if (astNode.kind === \"set\") return members.includes(\"set\");\n }\n return false;\n };\n }\n if (typeof suffix === \"string\") {\n const suffixString = suffix;\n suffix = (name) => name + suffixString;\n }\n // Definition of the Plugin\n return {\n name: \"rolldown-plugin-access-privates\",\n transform: {\n // Filters to optimize the plugin by skipping modules that don't need to be transformed.\n filter: {\n id: idFilter,\n // if there is no need to add exports, we only need to process modules that have private class members.\n ...(canNotExport ? { code: \"#\" } : {}),\n },\n // Function implementing the transformation logic.\n handler: withMagicString(function (code, id, meta) {\n // If ast is provided in meta, use it. Otherwise, parse the code with the appropriate language based on the file extension.\n let ast = meta.ast !== undefined ? meta.ast : this.parse(code.original, { lang: id.endsWith(\".tsx\") ? \"tsx\" : id.endsWith(\".ts\") ? \"ts\" : id.endsWith(\".jsx\") ? \"jsx\" : \"js\" });\n const visitors: VisitorObject = {};\n // only add the visitors needed.\n if (!canNotExport) {\n // Visitor to add export keyword to top-level variable, function, and class declarations.\n visitors.Program = function (node) {\n for (const child of node.body) {\n if ((child.type !== \"VariableDeclaration\" && child.type !== \"FunctionDeclaration\" && child.type !== \"ClassDeclaration\") || child.declare) continue;\n if (!exports(id, child)) continue;\n code.appendLeft(child.start, \"export \");\n }\n };\n }\n if (!canNotPropertyDefinition) {\n // Visitor to add getter and setter for private fields defined with PropertyDefinition.\n visitors.PropertyDefinition = function (node) {\n if (node.type !== \"PropertyDefinition\" || node.key.type !== \"PrivateIdentifier\" || node.declare || node.override) return;\n if (!classMembers(id, node)) return;\n const name = suffix(node.key.name);\n code.appendRight(node.end, `\\n${node.static ? \"static \" : \"\"}get [\"${name}\"]() {return this.#${node.key.name};}`);\n code.appendRight(node.end, `\\n${node.static ? \"static \" : \"\"}set [\"${name}\"](value) {this.#${node.key.name} = value;}`);\n };\n }\n if (!canNotMethodDefinition) {\n // Visitor to add getter and setter for private fields defined with MethodDefinition.\n visitors.MethodDefinition = function (node) {\n if (node.type !== \"MethodDefinition\" || node.key.type !== \"PrivateIdentifier\" || node.override) return;\n if (!classMembers(id, node)) return;\n const name = suffix(node.key.name);\n switch (node.kind) {\n case \"method\":\n code.appendRight(node.end, `\\n${node.static ? \"static \" : \"\"}get [\"${name}\"]() {return this.#${node.key.name};}`);\n break;\n case \"get\":\n code.appendRight(node.end, `\\n${node.static ? \"static \" : \"\"}get [\"${name}\"]() {return this.#${node.key.name};}`);\n break;\n case \"set\":\n code.appendRight(node.end, `\\n${node.static ? \"static \" : \"\"}set [\"${name}\"](value) {this.#${node.key.name} = value;}`);\n break;\n }\n };\n }\n // Walk the AST with the defined visitors to apply the transformations.\n new Visitor(visitors).visit(ast);\n }),\n },\n };\n}\n"],"mappings":";;;;;AAKA,MAAM,gBAAgB;CACpB,UAAU;CACV,UAAU;CACV,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K,KAAK,SAAS,YAAY,GAAG,QAAQ,KAAK,qBAAqB,KAAK,IAAI,KAAK,IAAI;AACjH;MACF,KAAK;AACH,YAAK,YAAY,KAAK,KAAK,KAAK,KAAK,SAAS,YAAY,GAAG,QAAQ,KAAK,qBAAqB,KAAK,IAAI,KAAK,IAAI;AACjH;MACF,KAAK;AACH,YAAK,YAAY,KAAK,KAAK,KAAK,KAAK,SAAS,YAAY,GAAG,QAAQ,KAAK,mBAAmB,KAAK,IAAI,KAAK,YAAY;AACvH;;;AAKR,QAAI,QAAQ,SAAS,CAAC,MAAM,IAAI;KAChC;GACH;EACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { type HookFilter, type Plugin } from \"rolldown\";\nimport { withMagicString } from \"rolldown-string\";\nimport { Visitor, type ESTree, type ParserOptions, type VisitorObject } from \"rolldown/utils\";\nimport type { Plugin as VitePlugin } from \"vite-plus\";\n\n/** Map exports types to their corresponding AST node types. */\nconst exportsToType = {\n variable: \"VariableDeclaration\",\n function: \"FunctionDeclaration\",\n class: \"ClassDeclaration\",\n} as const;\n\n/**\n * A Vite plugin to generate accessors for private fields to allow testing them.\n * This plugin will generate getter and setter methods for private fields and methods, allowing you to access them in your tests.\n * For example, if you have a private field `#foo`, the plugin will generate `fooPrivate` getter and setter.\n * Also automatically exports all top-level variables, functions, and classes in the module, allowing you to import them in your tests without needing to use `export` in your source code.\n *\n * @param options - Options for the plugin.\n * @returns\n */\nexport default function AccessPrivates({\n exports = true,\n classMembers = true,\n suffix = \"Private\",\n idFilter = /\\.[jt]sx?$/,\n}: {\n /**\n * Whether to export all top-level variables, functions, and classes in the module.\n * Can be an array of \"variable\", \"function\", and \"class\", or a function that will be called with the module ID and AST node of each variable, function, or class declaration.\n *\n * @default true\n */\n exports?: (\"variable\" | \"function\" | \"class\")[] | boolean | ((id: string, astNode: ESTree.VariableDeclaration | ESTree.Function | ESTree.Class) => boolean) | undefined;\n /**\n * Which class members to generate accessors for.\n * Can be an array of \"method\", \"get\", \"set\", and \"property\", or a function that will be called with the module ID and AST node of each method or property definition.\n *\n * @default true\n */\n classMembers?: (\"method\" | \"get\" | \"set\" | \"property\")[] | boolean | ((id: string, astNode: ESTree.MethodDefinition | ESTree.PropertyDefinition) => boolean) | undefined;\n /**\n * The suffix to use for the generated accessors.\n * For example, if you have a private field `#foo`, the plugin will generate `fooPrivate` getter and setter.\n *\n * @default \"Private\"\n */\n suffix?: string | ((name: string) => string) | undefined;\n /**\n * Filter for which modules the plugin should apply.\n * Can be a string, a RegExp, an array of strings and RegExps, or an object with an `include` and `exclude` property, each of which can be a string, a RegExp, or an array of strings and RegExps.\n * The filter will be applied to the module ID.\n *\n * @default /\\.[jt]sx?$/\n */\n idFilter?: HookFilter[\"id\"] | undefined;\n} = {}): Plugin {\n // Calculate which code path can be optimized.\n const canNotExport = exports === false || (Array.isArray(exports) && exports.length === 0);\n const canNotPropertyDefinition = classMembers === false || (Array.isArray(classMembers) && (classMembers.length === 0 || !classMembers.includes(\"property\")));\n const canNotMethodDefinition = classMembers === false || (Array.isArray(classMembers) && (classMembers.length === 0 || !classMembers.some((m) => m === \"method\" || m === \"get\" || m === \"set\")));\n // Transform filters in to a unified format\n if (typeof exports === \"boolean\") {\n const shouldExport = exports;\n exports = () => shouldExport;\n } else if (Array.isArray(exports)) {\n const mappedExports: ESTree.Node[\"type\"][] = exports.map((e) => exportsToType[e]);\n exports = (_id, astNode) => mappedExports.includes(astNode.type);\n }\n if (typeof classMembers === \"boolean\") {\n const shouldGenerate = classMembers;\n classMembers = () => shouldGenerate;\n } else if (Array.isArray(classMembers)) {\n const members = classMembers;\n classMembers = (_id, astNode) => {\n if (astNode.type === \"PropertyDefinition\") return members.includes(\"property\");\n if (astNode.type === \"MethodDefinition\") {\n if (astNode.kind === \"method\") return members.includes(\"method\");\n if (astNode.kind === \"get\") return members.includes(\"get\");\n if (astNode.kind === \"set\") return members.includes(\"set\");\n }\n return false;\n };\n }\n if (typeof suffix === \"string\") {\n const suffixString = suffix;\n suffix = (name) => name + suffixString;\n }\n // Definition of the Plugin\n const plugin = {\n name: \"rolldown-plugin-access-privates\",\n transform: {\n // Filters to optimize the plugin by skipping modules that don't need to be transformed.\n filter: {\n id: idFilter,\n // if there is no need to add exports, we only need to process modules that have private class members.\n ...(canNotExport ? { code: \"#\" } : {}),\n },\n // Function implementing the transformation logic.\n handler: withMagicString(function (this: { parse(input: string, options?: ParserOptions | null): ESTree.Program }, code, id, meta?: { ssr?: boolean | undefined; ast?: ESTree.Program }) {\n // If ast is provided in meta, use it. Otherwise, parse the code with the appropriate language based on the file extension.\n let ast = meta?.ast !== undefined ? meta.ast : this.parse(code.original, { lang: id.endsWith(\".tsx\") ? \"tsx\" : id.endsWith(\".ts\") ? \"ts\" : id.endsWith(\".jsx\") ? \"jsx\" : \"js\" });\n const visitors: VisitorObject = {};\n // only add the visitors needed.\n if (!canNotExport) {\n // Visitor to add export keyword to top-level variable, function, and class declarations.\n visitors.Program = function (node) {\n for (const child of node.body) {\n if ((child.type !== \"VariableDeclaration\" && child.type !== \"FunctionDeclaration\" && child.type !== \"ClassDeclaration\") || child.declare) continue;\n if (!exports(id, child)) continue;\n code.appendLeft(child.start, \"export \");\n }\n };\n }\n if (!canNotPropertyDefinition) {\n // Visitor to add getter and setter for private fields defined with PropertyDefinition.\n visitors.PropertyDefinition = function (node) {\n if (node.type !== \"PropertyDefinition\" || node.key.type !== \"PrivateIdentifier\" || node.declare || node.override) return;\n if (!classMembers(id, node)) return;\n const name = suffix(node.key.name);\n code.appendRight(node.end, `\\n${node.static ? \"static \" : \"\"}get [\"${name}\"]() {return this.#${node.key.name};}`);\n code.appendRight(node.end, `\\n${node.static ? \"static \" : \"\"}set [\"${name}\"](value) {this.#${node.key.name} = value;}`);\n };\n }\n if (!canNotMethodDefinition) {\n // Visitor to add getter and setter for private fields defined with MethodDefinition.\n visitors.MethodDefinition = function (node) {\n if (node.type !== \"MethodDefinition\" || node.key.type !== \"PrivateIdentifier\" || node.override) return;\n if (!classMembers(id, node)) return;\n const name = suffix(node.key.name);\n switch (node.kind) {\n case \"method\":\n code.appendRight(node.end, `\\n${node.static ? \"static \" : \"\"}get [\"${name}\"]() {return this.#${node.key.name};}`);\n break;\n case \"get\":\n code.appendRight(node.end, `\\n${node.static ? \"static \" : \"\"}get [\"${name}\"]() {return this.#${node.key.name};}`);\n break;\n case \"set\":\n code.appendRight(node.end, `\\n${node.static ? \"static \" : \"\"}set [\"${name}\"](value) {this.#${node.key.name} = value;}`);\n break;\n }\n };\n }\n // Walk the AST with the defined visitors to apply the transformations.\n new Visitor(visitors).visit(ast);\n }),\n },\n } satisfies VitePlugin;\n return plugin as Plugin;\n}\n"],"mappings":";;;;;AAMA,MAAM,gBAAgB;CACpB,UAAU;CACV,UAAU;CACV,OAAO;AACT;;;;;;;;;;AAWA,SAAwB,eAAe,EACrC,UAAU,MACV,eAAe,MACf,SAAS,WACT,WAAW,iBA+BT,CAAC,GAAW;CAEd,MAAM,eAAe,YAAY,SAAU,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW;CACxF,MAAM,2BAA2B,iBAAiB,SAAU,MAAM,QAAQ,YAAY,MAAM,aAAa,WAAW,KAAK,CAAC,aAAa,SAAS,UAAU;CAC1J,MAAM,yBAAyB,iBAAiB,SAAU,MAAM,QAAQ,YAAY,MAAM,aAAa,WAAW,KAAK,CAAC,aAAa,MAAM,MAAM,MAAM,YAAY,MAAM,SAAS,MAAM,KAAK;CAE7L,IAAI,OAAO,YAAY,WAAW;EAChC,MAAM,eAAe;EACrB,gBAAgB;CAClB,OAAO,IAAI,MAAM,QAAQ,OAAO,GAAG;EACjC,MAAM,gBAAuC,QAAQ,KAAK,MAAM,cAAc,EAAE;EAChF,WAAW,KAAK,YAAY,cAAc,SAAS,QAAQ,IAAI;CACjE;CACA,IAAI,OAAO,iBAAiB,WAAW;EACrC,MAAM,iBAAiB;EACvB,qBAAqB;CACvB,OAAO,IAAI,MAAM,QA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,CAAC,aAAa,IAAI,IAAI,GAAG;KAC7B,MAAM,OAAO,OAAO,KAAK,IAAI,IAAI;KACjC,KAAK,YAAY,KAAK,KAAK,KAAK,KAAK,SAAS,YAAY,GAAG,QAAQ,KAAK,qBAAqB,KAAK,IAAI,KAAK,GAAG;KAChH,KAAK,YAAY,KAAK,KAAK,KAAK,KAAK,SAAS,YAAY,GAAG,QAAQ,KAAK,mBAAmB,KAAK,IAAI,KAAK,WAAW;IACxH;IAEF,IAAI,CAAC,wBAEH,SAAS,mBAAmB,SAAU,MAAM;KAC1C,IAAI,KAAK,SAAS,sBAAsB,KAAK,IAAI,SAAS,uBAAuB,KAAK,UAAU;KAChG,IAAI,CAAC,aAAa,IAAI,IAAI,GAAG;KAC7B,MAAM,OAAO,OAAO,KAAK,IAAI,IAAI;KACjC,QAAQ,KAAK,MAAb;MACE,KAAK;OACH,KAAK,YAAY,KAAK,KAAK,KAAK,KAAK,SAAS,YAAY,GAAG,QAAQ,KAAK,qBAAqB,KAAK,IAAI,KAAK,GAAG;OAChH;MACF,KAAK;OACH,KAAK,YAAY,KAAK,KAAK,KAAK,KAAK,SAAS,YAAY,GAAG,QAAQ,KAAK,qBAAqB,KAAK,IAAI,KAAK,GAAG;OAChH;MACF,KAAK;OACH,KAAK,YAAY,KAAK,KAAK,KAAK,KAAK,SAAS,YAAY,GAAG,QAAQ,KAAK,mBAAmB,KAAK,IAAI,KAAK,WAAW;OACtH;KACJ;IACF;IAGF,IAAI,QAAQ,QAAQ,CAAC,CAAC,MAAM,GAAG;GACjC,CAAC;EACH;CAEU;AACd"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-access-privates",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Rolldown Plugin to add accessors for class Private Fields",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessors",
|
|
@@ -35,15 +35,10 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@typescript/native-preview": "^7.0.0-dev.20260324.1",
|
|
38
|
-
"vite-plus": "^0.1
|
|
38
|
+
"vite-plus": "^0.2.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"rolldown": ">=1.0.0
|
|
42
|
-
},
|
|
43
|
-
"peerDependenciesMeta": {
|
|
44
|
-
"vite": {
|
|
45
|
-
"optional": true
|
|
46
|
-
}
|
|
41
|
+
"rolldown": ">=1.0.0"
|
|
47
42
|
},
|
|
48
43
|
"compatiblePackages": {
|
|
49
44
|
"schemaVersion": 1,
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type HookFilter, type Plugin } from "rolldown";
|
|
2
2
|
import { withMagicString } from "rolldown-string";
|
|
3
|
-
import { Visitor, type ESTree, type VisitorObject } from "rolldown/utils";
|
|
3
|
+
import { Visitor, type ESTree, type ParserOptions, type VisitorObject } from "rolldown/utils";
|
|
4
|
+
import type { Plugin as VitePlugin } from "vite-plus";
|
|
4
5
|
|
|
5
6
|
/** Map exports types to their corresponding AST node types. */
|
|
6
7
|
const exportsToType = {
|
|
@@ -86,7 +87,7 @@ export default function AccessPrivates({
|
|
|
86
87
|
suffix = (name) => name + suffixString;
|
|
87
88
|
}
|
|
88
89
|
// Definition of the Plugin
|
|
89
|
-
|
|
90
|
+
const plugin = {
|
|
90
91
|
name: "rolldown-plugin-access-privates",
|
|
91
92
|
transform: {
|
|
92
93
|
// Filters to optimize the plugin by skipping modules that don't need to be transformed.
|
|
@@ -96,9 +97,9 @@ export default function AccessPrivates({
|
|
|
96
97
|
...(canNotExport ? { code: "#" } : {}),
|
|
97
98
|
},
|
|
98
99
|
// Function implementing the transformation logic.
|
|
99
|
-
handler: withMagicString(function (code, id, meta) {
|
|
100
|
+
handler: withMagicString(function (this: { parse(input: string, options?: ParserOptions | null): ESTree.Program }, code, id, meta?: { ssr?: boolean | undefined; ast?: ESTree.Program }) {
|
|
100
101
|
// If ast is provided in meta, use it. Otherwise, parse the code with the appropriate language based on the file extension.
|
|
101
|
-
let ast = meta
|
|
102
|
+
let ast = meta?.ast !== undefined ? meta.ast : this.parse(code.original, { lang: id.endsWith(".tsx") ? "tsx" : id.endsWith(".ts") ? "ts" : id.endsWith(".jsx") ? "jsx" : "js" });
|
|
102
103
|
const visitors: VisitorObject = {};
|
|
103
104
|
// only add the visitors needed.
|
|
104
105
|
if (!canNotExport) {
|
|
@@ -144,5 +145,6 @@ export default function AccessPrivates({
|
|
|
144
145
|
new Visitor(visitors).visit(ast);
|
|
145
146
|
}),
|
|
146
147
|
},
|
|
147
|
-
};
|
|
148
|
+
} satisfies VitePlugin;
|
|
149
|
+
return plugin as Plugin;
|
|
148
150
|
}
|