@wuchale/jsx 0.7.2 → 0.7.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.
@@ -4,7 +4,7 @@ import type * as Estree from 'acorn';
4
4
  import { Transformer } from 'wuchale/adapter-vanilla';
5
5
  import type { IndexTracker, HeuristicFunc, TransformOutput, RuntimeConf, CatalogExpr } from 'wuchale';
6
6
  import { MixedVisitor, type CommentDirectives } from "wuchale/adapter-utils";
7
- export declare function parseScript(content: string): [Estree.Program, Estree.Comment[][]];
7
+ export declare function parseScriptJSX(content: string): [Estree.Program, Estree.Comment[][]];
8
8
  type MixedNodesTypes = JX.JSXElement | JX.JSXFragment | JX.JSXText | JX.JSXExpressionContainer | JX.JSXSpreadChild;
9
9
  export type JSXLib = 'default' | 'solidjs';
10
10
  export declare class JSXTransformer extends Transformer {
@@ -2,11 +2,10 @@ import MagicString from 'magic-string';
2
2
  import { Parser } from 'acorn';
3
3
  import { Message } from 'wuchale';
4
4
  import { tsPlugin } from '@sveltejs/acorn-typescript';
5
- import jsx from 'acorn-jsx';
6
- import { Transformer, scriptParseOptionsWithComments } from 'wuchale/adapter-vanilla';
5
+ import { Transformer, scriptParseOptionsWithComments, parseScript } from 'wuchale/adapter-vanilla';
7
6
  import { nonWhitespaceText, MixedVisitor, processCommentDirectives } from "wuchale/adapter-utils";
8
- const JsxParser = Parser.extend(tsPlugin(), jsx());
9
- export function parseScript(content) {
7
+ const JsxParser = Parser.extend(tsPlugin({ jsx: true }));
8
+ export function parseScriptJSX(content) {
10
9
  const [opts, comments] = scriptParseOptionsWithComments();
11
10
  return [JsxParser.parse(content, opts), comments];
12
11
  }
@@ -219,7 +218,8 @@ export class JSXTransformer extends Transformer {
219
218
  return msgs;
220
219
  };
221
220
  transformJx = (lib) => {
222
- const [ast, comments] = parseScript(this.content);
221
+ // jsx vs type casting is not ambiguous in all files except .ts files
222
+ const [ast, comments] = (this.filename.endsWith('.ts') ? parseScript : parseScriptJSX)(this.content);
223
223
  this.comments = comments;
224
224
  this.mstr = new MagicString(this.content);
225
225
  this.mixedVisitor = this.initMixedVisitor();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/jsx",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Protobuf-like i18n from plain code: JSX adapter",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -71,7 +71,6 @@
71
71
  "dependencies": {
72
72
  "@sveltejs/acorn-typescript": "^1.0.5",
73
73
  "acorn": "^8.15.0",
74
- "acorn-jsx": "^5.3.2",
75
74
  "wuchale": "^0.16.5"
76
75
  },
77
76
  "devDependencies": {