google / closure-compiler

A JavaScript checker and optimizer.

Home Page:https://developers.google.com/closure/compiler/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot convert ECMASCRIPT_2018 feature "RegExp unicode property escape"

haraleib opened this issue · comments

I wonder if there is a reason why google closure-compiler can't convert the following snippet while Babel can do it. (Snippet available with the links below)

Maybe somebody can help me out here or have some input concerning this issue.

Google closure-compiler:
https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520SIMPLE_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F%252F%2520ADD%2520YOUR%2520CODE%2520HERE%250Afunction%2520proper(ast%252C%2520state)%2520%257B%250A%2520%2520%2520%2520return%2520this.runFunction(ast.args%252C%2520state%252C%2520this.metadata('PROPER')%252C%2520arg%2520%253D%253E%2520%257B%250A%2520%2520%2520%2520%2520%2520return%2520arg.replace(%252F%255Cp%257BL%257D%252B%252Fgu%252C%2520word%2520%253D%253E%2520word.charAt(0).toUpperCase()%2520%252B%2520word.substring(1).toLowerCase())%253B%250A%2520%2520%2520%2520%257D)%253B%250A%257D%250A%250A,

Babel:
https://babeljs.io/repl#?browsers=&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=GYVwdgxgLglg9mABABwE52QU1QCgIYDOUANIkXlJgJSIDeAUIk4qplCKklABYwEB0qcADFw0eGHxF-eVAHMCpcpVI8-_ALZs8AEwp4cAcgAKAJQDyxgKKnDVUrLmIAvAD46jZk1btOiR4KYyAA2eBCYOAD0ADrItAAyAL4A1JFyIKQA7nCoOi7u2bn8ENyyAIJQOAAMVPxQcACqyFioAMKEETTJiIU6_AQgAEZEqDBgcjgAjLX18XCZ2O0EnVQA3J5MiWv0iUA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Cstage-2&prettier=false&targets=&version=7.22.17&externalPlugins=&assumptions=%7B%7D

Hi @haraleib, Closure Compiler doesn't have any support for transpiling regular expressions to work on older browsers. I'll leave this open as a feature request but I think it's unlikely to change.

As the Babel example shows, transpiling regular expression syntax can be very verbose, and Closure Compiler's design is more focused on code size minification.

I think your options are to use Babel, avoid newer regex syntax, or set a newer --language_out.

@lauraharker thank you for your explanation. Would be a cool feature. But nevertheless everything is clear for me.