The MDN website gives examples of matching patterns with unicode support, e.g.
const sentence = 'A ticket to 大阪 costs ¥2000 👌.';
const regexpCurrencyOrPunctuation = /\p{Sc}|\p{P}/gu;
console.log(sentence.match(regexpCurrencyOrPunctuation));
It works fine on stackoverflow as a snippet.
However, in a javascript codesandbox, the code throws an error:
/src/index.js: Unknown property: Sc
In a Next.js codesandbox it also throws the same error.
On the other hand, on regex101 website the pattern is correctly matched to the sentence, with ECMAScript flavor and with "gu" flag.
Additionally, in my real world Next.js Typescript project, a pattern /\P{L}/gu worked fine until yesterday when I upgraded all dependencies to latest versions. Now it throws similar error with strict mode set to true in tsconfig.json. With strict mode set to false it still works fine.
Why is this error occurring and how to use the /\p{Sc}|\p{P}/gu or /\P{L}/gu regex pattern in code?
Based on the documentation, Sc is a non-binary property. Which means you can't just use \p{Sc}; you have to use \p{Sc=some_script_name}, where the script name is taken from here.
Unfortunately, it's a bug in next.js: https://github.com/vercel/next.js/issues/19303
Related
I get a Uncaught (in promise) TypeError: second argument must be an object error when I run the following code:
async function loadWasm(url) {
const fetchPromise = fetch(url)
const { module, instance } = await WebAssembly.instantiateStreaming(fetchPromise)
// [...]
}
loadWasm('http://localhost:3000/path/to/file.wasm')
Looking at the documentation, it says that the second argument of WebAssembly.instantiateStreaming (importObject) is optional, so I don't understand why the browser makes it mandatory nonetheless?
I've tested this in Firefox 78.7.0esr (64-bit) and Chrome 88.0.4324.96 (Official Build) (64-bit). In case it's of any importance, the code is transpiled with webpack 5 in a ruby on rails 6.1 application.
Update:
I opened an issue on mdn's github repository thinking the documentation might need an update. So far it seems the documentation is good so it might be an implementation issue. To be confirmed.
Update:
It's neither an implementation issue nor a documentation mistake. I posted my conclusion about this issue in the answer below.
https://github.com/WebAssembly/spec/issues/1284#issuecomment-772286062
It is required only if the module you're instantiating actually imports something.
It's marked as optional in the documentation because it's not always needed, not because we have the choice to provide it or not. It's the wasm package that dictates whether it is optional or required.
I am trying to make the following unicode regular expression work in nodejs, but all I get is an invalid escape error. I can't figure out, what to escape here or if this for some reason doesn't work at all in node. This is my original regex:
/([\p{L}|\-]+)/ug
If I escape the \p like \\p, the regex doesn't work anymore (outputs only p,L and -)
This works in chrome, so it should work in node somehow too, right? Thanks for your help.
var str = "thÛs Ís spå-rtÅ!";
console.log(str.match(/([\p{L}|\-]+)/ug))
A quick look through the nodejs changelog revealed this PR:
https://github.com/nodejs/node/pull/19052
which most notably states:
RegExp Unicode Property Escapes are at stage 4 and will be included in ES2018. They are available since V8 6.4 without a flag so they will be unflagged in Node.js v10. They are also available under the --harmony_regexp_property flag in Node.js v6-v9 and under the --harmony flag in Node.js v8-v9.
So by the look of it, if you are on node v6-v9, you can enable this feature by running node with a flag. For example, this works for me on node v8.11.3:
node --harmony regex-test.js
(where regex-test.js contains your sample code). Running this without the flag gives your Invalid escape error.
If you can update your node version to v10+, no flag is needed.
If you are going to use --harmony flag please consider this
As mentioned in the Node Documentation, --harmony flag enables the non-stable but to be soon stable features of ES6
The current behaviour of the --harmony flag on Node.js is to enable staged features only. After all, it is now a synonym of --es_staging. As mentioned above, these are completed features that have not been considered stable yet. If you want to play safe, especially on production environments, consider removing this runtime flag until it ships by default on V8 and, consequently, on Node.js. If you keep this enabled, you should be prepared for further Node.js upgrades to break your code if V8 changes their semantics to more closely follow the standard.
here is the link for that
https://nodejs.org/en/docs/es6/#:~:text=The%20current%20behaviour%20of%20the,to%20enable%20staged%20features%20only.&text=If%20you%20want%20to%20play,js.
I recently updated my PHPStorm to 2017.1, after the update I saw some new errors pop up.
In this piece of code:
var $find_ean = $('.' + scan_string);
Screenshot of the syntax highlighting
I get this an identifier expected error, to my knowledge concatenating a selector for jQuery is allowed. I have not found the corresponding inspection to disable this or found a proper way to resolve this error. Changing the code to
var selector = '.' + scan_string;
var $find_ean = $(selector);
Removes the error from the inspection, but I'm not really keen on the idea that I have to add in an extra line of code to resolve the inspection.
Which inspection rule is responsible for marking this code as an error?
Is there a proper way of resolving this besides adding in an extra line of code to satisfy the inspection?
JavaScript language version is set to ECMAScript 5.1
PHPStorm version is 2017.1 EAP
If there is any other information needed to find a solution please let me know I will update my question.
Thanks in advance.
A lot of people are reporting this kind of issues in JavaScript files - link. Some of them are: "a term expected", "unexpected token", "an identifier expected". These inspection issues are related with PhpStorm 2017.1 version. They should release update 2017.1.1 next week where these issues should be resolved.
Rendering DraftJS Editor on IE11 gives the following error -
Invariant Violation: PluginEditor.render(): A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object.
This same setup works fine in Chrome/FF. We already use babel for transpiling ES6.
A related Github thread (https://github.com/facebook/draft-js/issues/296) mentioned multiple versions of React (since draft includes version 15+) while my app uses v0.14... I tried this, but upgrading isn't feasible right now)
The documentation mentions using es6-shim along with es5-shim (https://facebook.github.io/draft-js/docs/advanced-topics-issues-and-pitfalls.html#polyfills). I tried this but it didn't help. I get the same error.
Anything else I might be missing? Looking forward to your inputs.
I want to use Reflect.parse in my JavaScript in Firefox.
MDN says to import this into the global object via
Components.utils.import("resource://gre/modules/reflect.jsm")
However, this results in the following error message:
Error: Permission denied for <file://> to get property XPCComponents.utils
I have tried this in Firefox 11 and Aurora.
How can I get access to Reflect.parse?
EDIT:
The error message is due to the following fragment:
Component.utils
There is no real solution to this problem. The documentation on Reflect.parse in the wiki is misleading, to say the least.
If you want a "pure" JavaScript solution in SpiderMonkey/Firefox, don't rely on Reflect.parse.
I see a lot of projects using the parser from Narcissus and I should have done the same.
EDIT: The Esprima project is an excellent implementation of the Mozilla Parser API. After replacing Reflect.parse with esprima.parse all my 150+ test cases were still green, except for 5 or so dealing with non-standard SpiderMonkey extensions like let expressions (which I find pretty impressive).