@ktjs/rollup-plugin-ktjsx 0.2.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 kasukabe tsumugi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ import { Plugin } from 'rollup';
2
+
3
+ type Filter = RegExp | ((id: string) => boolean);
4
+ interface RollupKTjsxOptions {
5
+ include?: Filter;
6
+ exclude?: Filter;
7
+ babelConfig?: Record<string, unknown>;
8
+ }
9
+ declare function rollupKTjsx(options?: RollupKTjsxOptions): Plugin;
10
+
11
+ export { rollupKTjsx as default, rollupKTjsx };
12
+ export type { RollupKTjsxOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,54 @@
1
+ import { transformWithKTjsx } from '@ktjs/transformer';
2
+
3
+ const DEFAULT_INCLUDE_RE = /\.[cm]?[jt]sx$/;
4
+ const NODE_MODULES_RE = /\/node_modules\//;
5
+ const QUERY_RE = /\?.*$/;
6
+ const stripQuery = (id) => id.replace(QUERY_RE, '');
7
+ const matchFilter = (filter, id) => {
8
+ if (!filter) {
9
+ return false;
10
+ }
11
+ if (typeof filter === 'function') {
12
+ return filter(id);
13
+ }
14
+ filter.lastIndex = 0;
15
+ return filter.test(id);
16
+ };
17
+ const shouldTransform = (id, include, exclude) => {
18
+ if (id.startsWith('\0') || NODE_MODULES_RE.test(id)) {
19
+ return false;
20
+ }
21
+ if (exclude && matchFilter(exclude, id)) {
22
+ return false;
23
+ }
24
+ if (include) {
25
+ return matchFilter(include, id);
26
+ }
27
+ return DEFAULT_INCLUDE_RE.test(id);
28
+ };
29
+ function rollupKTjsx(options = {}) {
30
+ return {
31
+ name: 'ktjs:rollup-plugin-ktjsx',
32
+ async transform(code, id) {
33
+ const cleanId = stripQuery(id);
34
+ if (!shouldTransform(cleanId, options.include, options.exclude)) {
35
+ return null;
36
+ }
37
+ const result = await transformWithKTjsx(code, {
38
+ filename: cleanId,
39
+ sourceFileName: cleanId,
40
+ ...options.babelConfig,
41
+ });
42
+ if (!result?.code) {
43
+ return null;
44
+ }
45
+ return {
46
+ code: result.code,
47
+ map: result.map ?? null,
48
+ };
49
+ },
50
+ };
51
+ }
52
+
53
+ export { rollupKTjsx as default, rollupKTjsx };
54
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/index.ts"],"sourcesContent":["import type { Plugin } from 'rollup';\nimport { transformWithKTjsx, type KTjsxTransformOptions } from '@ktjs/transformer';\n\ntype Filter = RegExp | ((id: string) => boolean);\n\nexport interface RollupKTjsxOptions {\n include?: Filter;\n exclude?: Filter;\n babelConfig?: Record<string, unknown>;\n}\n\nconst DEFAULT_INCLUDE_RE = /\\.[cm]?[jt]sx$/;\nconst NODE_MODULES_RE = /\\/node_modules\\//;\nconst QUERY_RE = /\\?.*$/;\ntype InternalTransformOptions = Omit<KTjsxTransformOptions, 'filename' | 'sourceFileName'>;\n\nconst stripQuery = (id: string) => id.replace(QUERY_RE, '');\n\nconst matchFilter = (filter: Filter | undefined, id: string): boolean => {\n if (!filter) {\n return false;\n }\n\n if (typeof filter === 'function') {\n return filter(id);\n }\n\n filter.lastIndex = 0;\n return filter.test(id);\n};\n\nconst shouldTransform = (id: string, include?: Filter, exclude?: Filter): boolean => {\n if (id.startsWith('\\0') || NODE_MODULES_RE.test(id)) {\n return false;\n }\n\n if (exclude && matchFilter(exclude, id)) {\n return false;\n }\n\n if (include) {\n return matchFilter(include, id);\n }\n\n return DEFAULT_INCLUDE_RE.test(id);\n};\n\nexport function rollupKTjsx(options: RollupKTjsxOptions = {}): Plugin {\n return {\n name: 'ktjs:rollup-plugin-ktjsx',\n async transform(code, id) {\n const cleanId = stripQuery(id);\n if (!shouldTransform(cleanId, options.include, options.exclude)) {\n return null;\n }\n\n const result = await transformWithKTjsx(code, {\n filename: cleanId,\n sourceFileName: cleanId,\n ...(options.babelConfig as InternalTransformOptions),\n });\n\n if (!result?.code) {\n return null;\n }\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n },\n };\n}\n\nexport default rollupKTjsx;\n"],"names":[],"mappings":";;AAWA,MAAM,kBAAkB,GAAG,gBAAgB;AAC3C,MAAM,eAAe,GAAG,kBAAkB;AAC1C,MAAM,QAAQ,GAAG,OAAO;AAGxB,MAAM,UAAU,GAAG,CAAC,EAAU,KAAK,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;AAE3D,MAAM,WAAW,GAAG,CAAC,MAA0B,EAAE,EAAU,KAAa;IACtE,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;AAChC,QAAA,OAAO,MAAM,CAAC,EAAE,CAAC;IACnB;AAEA,IAAA,MAAM,CAAC,SAAS,GA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C;KACF;AACH;;;;"}
@@ -0,0 +1,10 @@
1
+ import type { Plugin } from 'rollup';
2
+ type Filter = RegExp | ((id: string) => boolean);
3
+ export interface RollupKTjsxOptions {
4
+ include?: Filter;
5
+ exclude?: Filter;
6
+ babelConfig?: Record<string, unknown>;
7
+ }
8
+ export declare function rollupKTjsx(options?: RollupKTjsxOptions): Plugin;
9
+ export default rollupKTjsx;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGrC,KAAK,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAsCD,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,MAAM,CAyBpE;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { NodePath } from '@babel/core';
2
+ import * as t from '@babel/types';
3
+ export declare function transformConditionalChains(path: NodePath<t.JSXElement>): void;
4
+ //# sourceMappingURL=if-else.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if-else.d.ts","sourceRoot":"","sources":["../../../../transformer/src/if-else.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAiFlC,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QA8DtE"}
@@ -0,0 +1,4 @@
1
+ export { default, transformerKTjsx } from './plugin.js';
2
+ export type { KTjsxTransformOptions } from './transform.js';
3
+ export { transformWithKTjsx } from './transform.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../transformer/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type NodePath } from '@babel/core';
2
+ import * as t from '@babel/types';
3
+ export declare function validateDirectiveCombinations(path: NodePath<t.JSXElement>): void;
4
+ export declare function transformKFor(path: NodePath<t.JSXElement>): boolean;
5
+ //# sourceMappingURL=k-for.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"k-for.d.ts","sourceRoot":"","sources":["../../../../transformer/src/k-for.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAWlC,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAkBzE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,OAAO,CAqCnE"}
@@ -0,0 +1,4 @@
1
+ import type { PluginObj } from '@babel/core';
2
+ export declare function transformerKTjsx(): PluginObj;
3
+ export default transformerKTjsx;
4
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../transformer/src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAK7C,wBAAgB,gBAAgB,IAAI,SAAS,CAgB5C;AAED,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { NodePath } from '@babel/core';
2
+ import * as t from '@babel/types';
3
+ export declare function addFlagToSvgMathMLElement(path: NodePath<t.JSXElement>): void;
4
+ //# sourceMappingURL=svg-mathml-flag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg-mathml-flag.d.ts","sourceRoot":"","sources":["../../../../transformer/src/svg-mathml-flag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAUlC,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAiFrE"}
@@ -0,0 +1,8 @@
1
+ import { type TransformOptions } from '@babel/core';
2
+ type ReservedTransformOptions = 'ast' | 'babelrc' | 'configFile' | 'parserOpts' | 'plugins' | 'sourceMaps';
3
+ export type KTjsxTransformOptions = Omit<TransformOptions, ReservedTransformOptions> & {
4
+ parserPlugins?: NonNullable<TransformOptions['parserOpts']>['plugins'];
5
+ };
6
+ export declare function transformWithKTjsx(code: string, options?: KTjsxTransformOptions): Promise<import("@babel/core").BabelFileResult>;
7
+ export {};
8
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../../transformer/src/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAKpE,KAAK,wBAAwB,GACzB,KAAK,GACL,SAAS,GACT,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,YAAY,CAAC;AAEjB,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,gBAAgB,EAAE,wBAAwB,CAAC,GAAG;IACrF,aAAa,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;CACxE,CAAC;AAEF,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,kDAezF"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@ktjs/rollup-plugin-ktjsx",
3
+ "version": "0.2.1",
4
+ "description": "Rollup plugin that applies KT.js JSX transforms.",
5
+ "description_zh": "用于应用 KT.js JSX 转换的 Rollup 插件。",
6
+ "type": "module",
7
+ "main": "dist/index.mjs",
8
+ "module": "dist/index.mjs",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.mjs",
14
+ "default": "./dist/index.mjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "author": {
21
+ "name": "Kasukabe Tsumugi",
22
+ "email": "futami16237@gmail.com"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/ktjs/kt.js"
27
+ },
28
+ "license": "MIT",
29
+ "dependencies": {
30
+ "@ktjs/transformer": "^*"
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5.9.3",
34
+ "vitest": "^4.0.18"
35
+ },
36
+ "peerDependencies": {
37
+ "rollup": "^3.0.0 || ^4.0.0"
38
+ }
39
+ }