typenative 0.6.1 → 0.6.2

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/CHANGELOG.md CHANGED
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.2] - 2026-11-15
11
+
12
+ ### Fixed
13
+
14
+ - **Self-hosted native build:** `npm run build:native` failed with `cannot use
15
+ typedClass (variable of type bool) as string value`. The transpiler typed
16
+ `a && b` by its left operand, so a getter-lookup helper written as
17
+ `leftGoType?.startsWith('*') && leftGoType.slice(1)` became a `bool` in the
18
+ Go build. It is now written as a ternary that yields a string or
19
+ `undefined`.
20
+ - **`replace` with an inline `new RegExp(…, 'g')`:** only the first match was
21
+ replaced, because the `g` flag was only seen on a regex literal or a
22
+ `RegExp` read from a variable. Flags written out in `new RegExp(p, 'flags')`
23
+ are now read at compile time, and any other `RegExp` expression (a call's
24
+ result, flags computed at run time) is evaluated once and its `g` flag
25
+ tested at run time. The self-hosted compiler relied on this to map string
26
+ enums to `string` in `tnCallValueTyped`, so its build of
27
+ examples/react-compiler failed with `duplicate case func(string,
28
+ MemoizationLevel) MemoizationLevel in type switch`.
29
+
30
+ ### Changed
31
+
32
+ - **tsparser:** `github.com/go-json-experiment/json` bumped to v1.27.2.
33
+
10
34
  ## [0.6.1] - 2026-11-15
11
35
 
12
36
  ### Changed
package/bin/transpiler.js CHANGED
@@ -4820,7 +4820,7 @@ function visitNode(node, options = {}) {
4820
4820
  !leftGoType?.includes('struct{') &&
4821
4821
  !leftGoType?.startsWith('*[]')) {
4822
4822
  // (a plain function's this typed as a class: its getters too)
4823
- const typedClass = leftGoType?.startsWith('*') && leftGoType.slice(1).replace(/\[.*\]$/, '');
4823
+ const typedClass = leftGoType?.startsWith('*') ? leftGoType.slice(1).replace(/\[.*\]$/, '') : undefined;
4824
4824
  const className = typedClass && classNames.has(typedClass)
4825
4825
  ? typedClass
4826
4826
  : node.expression.kind === 'ThisKeyword'
@@ -21500,6 +21500,31 @@ function visitRegexReplace(node) {
21500
21500
  // (an expression read twice must be pure: a name, fields, a Record lookup)
21501
21501
  else if (reIsWrapper && /^[\w.]+(\.Get\("[^"\\]*"\))?[\w.]*$/.test(re))
21502
21502
  isGlobal = `${re}.global`;
21503
+ else if (reIsWrapper) {
21504
+ // new RegExp(p, 'g…') written out: its flags are known here
21505
+ const flags = newRegExpLiteralFlags(pattern);
21506
+ if (flags !== undefined)
21507
+ isGlobal = flags.includes('g') ? 'true' : 'false';
21508
+ // any other RegExp (a call's result, new RegExp(p, flags)): evaluated
21509
+ // once, its g flag tested at run time
21510
+ else
21511
+ return `func() string { __rx := ${re}; return ${emitRegexReplace(pattern, replacement, target, reIsWrapper, '__rx', '__rx.global')} }()`;
21512
+ }
21513
+ return emitRegexReplace(pattern, replacement, target, reIsWrapper, re, isGlobal);
21514
+ }
21515
+ // The flags of new RegExp(p) / new RegExp(p, 'literal flags'); undefined for
21516
+ // any other expression or flags computed at run time
21517
+ function newRegExpLiteralFlags(node) {
21518
+ const expr = unwrapParentheses(node);
21519
+ if (!isNewExpression(expr) || !isIdentifier(expr.expression) || expr.expression.text !== 'RegExp')
21520
+ return undefined;
21521
+ const args = expr.arguments ?? [];
21522
+ if (args.length < 2)
21523
+ return args.length === 1 && isRegularExpressionLiteral(unwrapParentheses(args[0])) ? undefined : '';
21524
+ const flags = unwrapParentheses(args[1]);
21525
+ return isStringLiteral(flags) || isNoSubstitutionTemplateLiteral(flags) ? flags.text : undefined;
21526
+ }
21527
+ function emitRegexReplace(pattern, replacement, target, reIsWrapper, re, isGlobal) {
21503
21528
  importedPackages.add('regexp');
21504
21529
  if (isArrowFunction(replacement) || isFunctionExpression(replacement)) {
21505
21530
  useHelper('regexReplaceFunc');
package/bin/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/gen-version.mjs — do not edit.
2
- export const VERSION = '0.6.1';
2
+ export const VERSION = '0.6.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typenative",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Build native applications using Typescript.",
5
5
  "type": "module",
6
6
  "bin": {
package/tsparser/go.mod CHANGED
@@ -5,7 +5,7 @@ go 1.26.0
5
5
  require github.com/buke/typescript-go-internal v0.0.2
6
6
 
7
7
  require (
8
- github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e // indirect
8
+ github.com/go-json-experiment/json v1.27.2 // indirect
9
9
  github.com/klauspost/cpuid/v2 v2.2.10 // indirect
10
10
  github.com/zeebo/xxh3 v1.1.0 // indirect
11
11
  golang.org/x/sync v0.20.0 // indirect
package/tsparser/go.sum CHANGED
@@ -1,7 +1,7 @@
1
1
  github.com/buke/typescript-go-internal v0.0.2 h1:JTHAXQfj1HVN4eXh7XqUWZurxjowXoE+5Ud8QLS4uRg=
2
2
  github.com/buke/typescript-go-internal v0.0.2/go.mod h1:nZjFbdZyxx5D9s/GafAh6ESVUy3GMAjNMMMBjVEqDgc=
3
- github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e h1:Lf/gRkoycfOBPa42vU2bbgPurFong6zXeFtPoxholzU=
4
- github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e/go.mod h1:uNVvRXArCGbZ508SxYYTC5v1JWoz2voff5pm25jU1Ok=
3
+ github.com/go-json-experiment/json v1.27.2 h1:rZIyqYh+Qq+nEa+Y5iwohr8h7G/MfLJqu2CD4/ZONqM=
4
+ github.com/go-json-experiment/json v1.27.2/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
5
5
  github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
6
6
  github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
7
7
  github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=