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
ssalbdivad2w ago
Would need a little more context to know what this is lol
CodeHz
CodeHz7d 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
ssalbdivad7d ago
Then you should probably transpile your code haha
CodeHz
CodeHz7d ago
It is generated code in runtime by arktype So we cannot transpile it
ssalbdivad
ssalbdivad7d ago
You can use jitless: true
CodeHz
CodeHz7d 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
ssalbdivad7d 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
CodeHz7d 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
ssalbdivad7d 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
CodeHz7d ago
yes, if do a proper transpile, we need store it in a local variable to prevent eval twice
ssalbdivad
ssalbdivad7d 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
ssalbdivad7d ago
Even .map is only 97% according to this haha
No description
CodeHz
CodeHz7d 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
ssalbdivad7d ago
Well I'll update it in the next release
Dimava
Dimava7d 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
Want results from more Discord servers?
Add your server