@wsxjs/wsx-vite-plugin 0.0.10 → 0.0.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wsxjs/wsx-vite-plugin",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Vite plugin for WSX Framework",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -31,7 +31,7 @@
31
31
  "@babel/plugin-transform-class-static-block": "^7.28.0",
32
32
  "@babel/preset-typescript": "^7.28.5",
33
33
  "@babel/types": "^7.28.1",
34
- "@wsxjs/wsx-core": "0.0.10"
34
+ "@wsxjs/wsx-core": "0.0.12"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@babel/traverse": "^7.28.5",
@@ -48,6 +48,9 @@
48
48
  "esbuild": ">=0.25.0",
49
49
  "vite": ">=4.0.0"
50
50
  },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
51
54
  "scripts": {
52
55
  "build": "tsup src/index.ts --format cjs,esm --dts --external esbuild --external @babel/core --external @babel/preset-typescript --external @babel/plugin-proposal-decorators --external @babel/plugin-proposal-class-properties --external @babel/plugin-transform-class-static-block --external @babel/types",
53
56
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch --external esbuild --external @babel/core --external @babel/preset-typescript --external @babel/plugin-proposal-decorators --external @babel/plugin-proposal-class-properties --external @babel/plugin-transform-class-static-block --external @babel/types",
@@ -48,6 +48,7 @@ export default function babelPluginWSXState(): PluginObj<WSXStatePluginPass> {
48
48
 
49
49
  for (const member of classBody.body) {
50
50
  // Debug: log member type
51
+
51
52
  console.info(
52
53
  ` - Member type: ${member.type}, key: ${member.type === "ClassProperty" || member.type === "ClassPrivateProperty" ? (member.key as any)?.name : "N/A"}`
53
54
  );
@@ -100,8 +101,24 @@ export default function babelPluginWSXState(): PluginObj<WSXStatePluginPass> {
100
101
  }
101
102
  );
102
103
 
103
- if (hasStateDecorator && member.value) {
104
+ if (hasStateDecorator) {
104
105
  const key = member.key.name;
106
+
107
+ // @state decorator requires an initial value
108
+ // This is opinionated: we need the value to determine if it's primitive or object/array
109
+ if (!member.value) {
110
+ throw path.buildCodeFrameError(
111
+ `@state decorator on property '${key}' requires an initial value.\n` +
112
+ `\n` +
113
+ `Examples:\n` +
114
+ ` @state private ${key} = ""; // for string\n` +
115
+ ` @state private ${key} = 0; // for number\n` +
116
+ ` @state private ${key} = {}; // for object\n` +
117
+ ` @state private ${key} = []; // for array\n` +
118
+ ` @state private ${key} = undefined; // for optional\n`
119
+ );
120
+ }
121
+
105
122
  const initialValue = member.value as t.Expression;
106
123
 
107
124
  // Determine if it's an object/array
@@ -137,9 +137,32 @@ export function vitePluginWSXWithBabel(options: WSXPluginOptions = {}): Plugin {
137
137
 
138
138
  if (babelResult && babelResult.code) {
139
139
  transformedCode = babelResult.code;
140
+ } else {
141
+ // Babel returned no code - critical error
142
+ throw new Error(
143
+ `[WSX Plugin] Babel transform returned no code for ${id}. ` +
144
+ `@state decorators will NOT be processed and will cause runtime errors. ` +
145
+ `Please check Babel configuration and plugin setup.`
146
+ );
140
147
  }
141
- } catch {
142
- // Babel transform failed, fallback to esbuild only
148
+ } catch (error) {
149
+ // Babel transform failed - this is critical
150
+ // If Babel fails, @state decorators won't be processed and will cause runtime errors
151
+ // Don't silently fallback - throw error to make it obvious
152
+ const errorMessage = error instanceof Error ? error.message : String(error);
153
+ throw new Error(
154
+ `[WSX Plugin] Babel transform failed for ${id}. ` +
155
+ `@state decorators will NOT be processed and will cause runtime errors. ` +
156
+ `\n\n` +
157
+ `Babel Error: ${errorMessage}` +
158
+ `\n\n` +
159
+ `This usually means:` +
160
+ `\n1. Babel plugins are not installed correctly` +
161
+ `\n2. Babel configuration is invalid` +
162
+ `\n3. File contains syntax errors that Babel cannot parse` +
163
+ `\n\n` +
164
+ `Please fix the Babel error above before continuing.`
165
+ );
143
166
  }
144
167
 
145
168
  // 2.5. Ensure JSX imports still exist after Babel transformation