A
arktype3mo ago
CodeHz

Got syntax error in some browser

Encountered an unexpected error while compiling your definition: .. I guess it related to the token ??= syntax
17 Replies
ssalbdivad
ssalbdivad3mo ago
Would need a little more context to know what this is lol
CodeHz
CodeHzOP3mo ago
https://github.com/arktypeio/arktype/blob/main/ark/schema/roots/alias.ts#L116 the ?. and ??= isn’t supported in some older browsers
GitHub
arktype/ark/schema/roots/alias.ts at main · arktypeio/arktype
TypeScript's 1:1 validator, optimized from editor to runtime - arktypeio/arktype
ssalbdivad
ssalbdivad3mo ago
Then you should probably transpile your code haha
CodeHz
CodeHzOP3mo ago
It is generated code in runtime by arktype So we cannot transpile it
ssalbdivad
ssalbdivad3mo ago
You can use jitless: true
CodeHz
CodeHzOP3mo ago
I just patched the source code and it is working again
diff --git a/out/roots/alias.js b/out/roots/alias.js
index 49a873ae99455726e8d6d619268ee6fe73b92ed5..99c3e9d7c0bb7f7104ee58b6ba6dffb4dee71034 100644
--- a/out/roots/alias.js
+++ b/out/roots/alias.js
@@ -54,8 +54,9 @@ export class AliasNode extends BaseRoot {
this.resolution.traverseApply(data, ctx);
};
compile(js) {
- js.if(`ctx.seen.${this.id}?.includes(data)`, () => js.return(true));
- js.line(`ctx.seen.${this.id} ??= []`).line(`ctx.seen.${this.id}.push(data)`);
+ js.if(`ctx.seen.${this.id} && ctx.seen.${this.id}.includes(data)`, () => js.return(true));
+ js.if(`ctx.seen.${this.id} == undefined`, () => js.line(`ctx.seen.${this.id} = []`))
+ js.line(`ctx.seen.${this.id}.push(data)`);
js.return(js.invoke(this.resolution));
}
}
diff --git a/out/roots/alias.js b/out/roots/alias.js
index 49a873ae99455726e8d6d619268ee6fe73b92ed5..99c3e9d7c0bb7f7104ee58b6ba6dffb4dee71034 100644
--- a/out/roots/alias.js
+++ b/out/roots/alias.js
@@ -54,8 +54,9 @@ export class AliasNode extends BaseRoot {
this.resolution.traverseApply(data, ctx);
};
compile(js) {
- js.if(`ctx.seen.${this.id}?.includes(data)`, () => js.return(true));
- js.line(`ctx.seen.${this.id} ??= []`).line(`ctx.seen.${this.id}.push(data)`);
+ js.if(`ctx.seen.${this.id} && ctx.seen.${this.id}.includes(data)`, () => js.return(true));
+ js.if(`ctx.seen.${this.id} == undefined`, () => js.line(`ctx.seen.${this.id} = []`))
+ js.line(`ctx.seen.${this.id}.push(data)`);
js.return(js.invoke(this.resolution));
}
}
I will make a PR if needed
ssalbdivad
ssalbdivad3mo ago
I guess I'll just change it locally since I'm making some changes to aliases anyways. Crazy you have to support such old browsers
CodeHz
CodeHzOP3mo ago
caniuse report this feature is only valid for 93.4% of global users... https://caniuse.com/?search=??%3D (and https://caniuse.com/?search=?.
ssalbdivad
ssalbdivad3mo ago
I guess it's different since it can't be transpiled easily Anyways, thanks for letting me know, hopefully I don't accidentally use it anywhere else
CodeHz
CodeHzOP3mo ago
yes, if do a proper transpile, we need store it in a local variable to prevent eval twice
ssalbdivad
ssalbdivad3mo ago
I only support back to Node18 within ArkType directly But yeah, didn't occur to me that transpiled code kind of needs a different standard
ssalbdivad
ssalbdivad3mo ago
Even .map is only 97% according to this haha
No description
CodeHz
CodeHzOP3mo ago
but it at least won't affect mobile user, they cannot upgrade the browser easily if you selected tracked mobile for .map you will get 99.91% + 0.09% = 100%
ssalbdivad
ssalbdivad3mo ago
Well I'll update it in the next release
Dimava
Dimava3mo ago
Do you have some even older browsers to try by chance? Would be interesting to see what the current limitations are 🤔 How do you even run all the tests in the browser, lemme see
CodeHz
CodeHzOP3mo ago
chrome 80 in android emulator, I use it as baseline
Dimava
Dimava3mo ago
oof 2020 looks fine enough
Want results from more Discord servers?
Add your server