@react-pug/swc-plugin-react-pug 0.1.0

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/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @react-pug/swc-plugin-react-pug
2
+
3
+ Programmatic SWC helper for transforming `pug\`...\`` tagged template literals before passing code to SWC.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i -D @react-pug/swc-plugin-react-pug @swc/core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { transformWithSwcReactPug } from '@react-pug/swc-plugin-react-pug'
15
+
16
+ const result = transformWithSwcReactPug(sourceCode, fileName, {
17
+ jsc: {
18
+ parser: { syntax: 'typescript', tsx: true },
19
+ transform: { react: { runtime: 'automatic' } }
20
+ },
21
+ sourceMaps: true
22
+ })
23
+ ```
24
+
25
+ ## Options
26
+
27
+ - `tagFunction`: tagged template function name, default `pug`
28
+ - `mode`: `runtime | languageService`, default `runtime`
29
+ - `requirePugImport`: boolean, default `false`
30
+ - `classShorthandProperty`: `auto | className | class | styleName`
31
+ - `classShorthandMerge`: `auto | concatenate | classnames`
32
+ - `startupjsCssxjs`: `never | auto | force`
33
+ - `componentPathFromUppercaseClassShorthand`: boolean, default `true`
34
+
35
+ Used `pug` import bindings are removed from transformed output automatically.
36
+
37
+ ## Exports
38
+
39
+ - `transformWithSwcReactPug(...)`
40
+ - `transformReactPugSourceForSwc(...)`
41
+ - diagnostic/range remapping helpers
42
+
43
+ Published output is in `dist/`.
@@ -0,0 +1,29 @@
1
+ import { type ClassAttributeOption, type ClassMergeOption, type GeneratedDiagnosticLike, type OffsetRange, type OriginalDiagnosticLocation, type PugDocument, type PugRegion, type StartupjsCssxjsOption } from '@react-pug/react-pug-core';
2
+ import { type Options as SwcOptions } from '@swc/core';
3
+ export type SwcPugCompileMode = 'runtime' | 'languageService';
4
+ export interface SwcReactPugOptions {
5
+ tagFunction?: string;
6
+ mode?: SwcPugCompileMode;
7
+ requirePugImport?: boolean;
8
+ classShorthandProperty?: ClassAttributeOption;
9
+ classShorthandMerge?: ClassMergeOption;
10
+ startupjsCssxjs?: StartupjsCssxjsOption;
11
+ componentPathFromUppercaseClassShorthand?: boolean;
12
+ }
13
+ export interface SwcReactPugMetadata {
14
+ document: PugDocument;
15
+ regions: PugRegion[];
16
+ }
17
+ export interface SwcReactPugTransformResult {
18
+ code: string;
19
+ metadata: SwcReactPugMetadata;
20
+ }
21
+ export interface SwcReactPugCompileResult extends SwcReactPugTransformResult {
22
+ swcCode: string;
23
+ swcMap?: string;
24
+ }
25
+ export declare function transformReactPugSourceForSwc(sourceText: string, fileName: string, options?: SwcReactPugOptions): SwcReactPugTransformResult;
26
+ export declare function mapSwcGeneratedDiagnosticToOriginal(metadata: SwcReactPugMetadata, diagnostic: GeneratedDiagnosticLike): OriginalDiagnosticLocation | null;
27
+ export declare function mapSwcGeneratedRangeToOriginal(metadata: SwcReactPugMetadata, generatedStart: number, generatedLength: number): OffsetRange | null;
28
+ export declare function transformWithSwcReactPug(sourceText: string, fileName: string, swcOptions?: SwcOptions, options?: SwcReactPugOptions): SwcReactPugCompileResult;
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,WAAW,EAChB,KAAK,0BAA0B,EAC/B,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAiB,KAAK,OAAO,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AAEtE,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,iBAAiB,CAAC;AAE9D,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,sBAAsB,CAAC,EAAE,oBAAoB,CAAC;IAC9C,mBAAmB,CAAC,EAAE,gBAAgB,CAAC;IACvC,eAAe,CAAC,EAAE,qBAAqB,CAAC;IACxC,wCAAwC,CAAC,EAAE,OAAO,CAAC;CACpD;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,WAAW,CAAC;IACtB,OAAO,EAAE,SAAS,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,mBAAmB,CAAC;CAC/B;AAED,MAAM,WAAW,wBAAyB,SAAQ,0BAA0B;IAC1E,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,kBAAuB,GAC/B,0BAA0B,CAkB5B;AAED,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,mBAAmB,EAC7B,UAAU,EAAE,uBAAuB,GAClC,0BAA0B,GAAG,IAAI,CAEnC;AAED,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,mBAAmB,EAC7B,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,GACtB,WAAW,GAAG,IAAI,CAEpB;AAED,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,UAAe,EAC3B,OAAO,GAAE,kBAAuB,GAC/B,wBAAwB,CA+B1B"}
package/dist/index.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformReactPugSourceForSwc = transformReactPugSourceForSwc;
4
+ exports.mapSwcGeneratedDiagnosticToOriginal = mapSwcGeneratedDiagnosticToOriginal;
5
+ exports.mapSwcGeneratedRangeToOriginal = mapSwcGeneratedRangeToOriginal;
6
+ exports.transformWithSwcReactPug = transformWithSwcReactPug;
7
+ const react_pug_core_1 = require("@react-pug/react-pug-core");
8
+ const core_1 = require("@swc/core");
9
+ function transformReactPugSourceForSwc(sourceText, fileName, options = {}) {
10
+ const transformed = (0, react_pug_core_1.transformSourceFile)(sourceText, fileName, {
11
+ tagFunction: options.tagFunction ?? 'pug',
12
+ compileMode: options.mode ?? 'runtime',
13
+ requirePugImport: options.requirePugImport ?? false,
14
+ classAttribute: options.classShorthandProperty ?? 'auto',
15
+ classMerge: options.classShorthandMerge ?? 'auto',
16
+ startupjsCssxjs: options.startupjsCssxjs ?? 'auto',
17
+ componentPathFromUppercaseClassShorthand: options.componentPathFromUppercaseClassShorthand ?? true,
18
+ });
19
+ return {
20
+ code: transformed.code,
21
+ metadata: {
22
+ document: transformed.document,
23
+ regions: transformed.regions,
24
+ },
25
+ };
26
+ }
27
+ function mapSwcGeneratedDiagnosticToOriginal(metadata, diagnostic) {
28
+ return (0, react_pug_core_1.mapGeneratedDiagnosticToOriginal)(metadata.document, diagnostic);
29
+ }
30
+ function mapSwcGeneratedRangeToOriginal(metadata, generatedStart, generatedLength) {
31
+ return (0, react_pug_core_1.mapGeneratedRangeToOriginal)(metadata.document, generatedStart, generatedLength);
32
+ }
33
+ function transformWithSwcReactPug(sourceText, fileName, swcOptions = {}, options = {}) {
34
+ const transformedCore = (0, react_pug_core_1.transformSourceFile)(sourceText, fileName, {
35
+ tagFunction: options.tagFunction ?? 'pug',
36
+ compileMode: options.mode ?? 'runtime',
37
+ requirePugImport: options.requirePugImport ?? false,
38
+ classAttribute: options.classShorthandProperty ?? 'auto',
39
+ classMerge: options.classShorthandMerge ?? 'auto',
40
+ startupjsCssxjs: options.startupjsCssxjs ?? 'auto',
41
+ componentPathFromUppercaseClassShorthand: options.componentPathFromUppercaseClassShorthand ?? true,
42
+ });
43
+ const transformed = {
44
+ code: transformedCore.code,
45
+ metadata: {
46
+ document: transformedCore.document,
47
+ regions: transformedCore.regions,
48
+ },
49
+ };
50
+ const inputSourceMap = (0, react_pug_core_1.createTransformSourceMap)(transformedCore, fileName);
51
+ const swcResult = (0, core_1.transformSync)(transformed.code, {
52
+ ...swcOptions,
53
+ filename: fileName,
54
+ sourceMaps: swcOptions.sourceMaps,
55
+ inputSourceMap: swcOptions.inputSourceMap ?? JSON.stringify(inputSourceMap),
56
+ });
57
+ return {
58
+ ...transformed,
59
+ swcCode: swcResult.code,
60
+ swcMap: swcResult.map,
61
+ };
62
+ }
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AA2CA,sEAsBC;AAED,kFAKC;AAED,wEAMC;AAED,4DAoCC;AAtHD,8DAamC;AACnC,oCAAsE;AA6BtE,SAAgB,6BAA6B,CAC3C,UAAkB,EAClB,QAAgB,EAChB,UAA8B,EAAE;IAEhC,MAAM,WAAW,GAAG,IAAA,oCAAmB,EAAC,UAAU,EAAE,QAAQ,EAAE;QAC5D,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,KAAK;QACzC,WAAW,EAAE,OAAO,CAAC,IAAI,IAAI,SAAS;QACtC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,KAAK;QACnD,cAAc,EAAE,OAAO,CAAC,sBAAsB,IAAI,MAAM;QACxD,UAAU,EAAE,OAAO,CAAC,mBAAmB,IAAI,MAAM;QACjD,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,MAAM;QAClD,wCAAwC,EAAE,OAAO,CAAC,wCAAwC,IAAI,IAAI;KACnG,CAAC,CAAC;IAEH,OAAO;QACL,IAAI,EAAE,WAAW,CAAC,IAAI;QACtB,QAAQ,EAAE;YACR,QAAQ,EAAE,WAAW,CAAC,QAAQ;YAC9B,OAAO,EAAE,WAAW,CAAC,OAAO;SAC7B;KACF,CAAC;AACJ,CAA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AAc,EAAG,UAAkB,CAAC,cAAc,IAAI,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;KACrF,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,WAAW;QACd,OAAO,EAAE,SAAS,CAAC,IAAI;QACvB,MAAM,EAAE,SAAS,CAAC,GAAG;KACtB,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@react-pug/swc-plugin-react-pug",
3
+ "version": "0.1.0",
4
+ "main": "./dist/index.js",
5
+ "types": "./dist/index.d.ts",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "scripts": {
10
+ "build": "npm --prefix ../.. run build -w @react-pug/react-pug-core && rm -rf dist && tsc -p tsconfig.build.json",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "dependencies": {
14
+ "@react-pug/react-pug-core": "^0.1.0"
15
+ },
16
+ "peerDependencies": {
17
+ "@swc/core": "^1.0.0"
18
+ },
19
+ "gitHead": "b4e9f09659dd4c70d0734759ea00710414fd8366"
20
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "baseUrl": ".",
6
+ "paths": {
7
+ "@react-pug/react-pug-core": [
8
+ "../react-pug-core/src/index.ts"
9
+ ]
10
+ }
11
+ },
12
+ "include": [
13
+ "src/**/*.ts"
14
+ ],
15
+ "exclude": [
16
+ "dist"
17
+ ]
18
+ }