@wuchale/jsx 0.7.3 → 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,10 +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 { Transformer, scriptParseOptionsWithComments } from 'wuchale/adapter-vanilla';
5
+ import { Transformer, scriptParseOptionsWithComments, parseScript } from 'wuchale/adapter-vanilla';
6
6
  import { nonWhitespaceText, MixedVisitor, processCommentDirectives } from "wuchale/adapter-utils";
7
7
  const JsxParser = Parser.extend(tsPlugin({ jsx: true }));
8
- export function parseScript(content) {
8
+ export function parseScriptJSX(content) {
9
9
  const [opts, comments] = scriptParseOptionsWithComments();
10
10
  return [JsxParser.parse(content, opts), comments];
11
11
  }
@@ -218,7 +218,8 @@ export class JSXTransformer extends Transformer {
218
218
  return msgs;
219
219
  };
220
220
  transformJx = (lib) => {
221
- 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);
222
223
  this.comments = comments;
223
224
  this.mstr = new MagicString(this.content);
224
225
  this.mixedVisitor = this.initMixedVisitor();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/jsx",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Protobuf-like i18n from plain code: JSX adapter",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",