Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform regex with 'su' flag, using dotAllFlag=false #26

Open
meowtec opened this issue Aug 17, 2019 · 4 comments
Open

Transform regex with 'su' flag, using dotAllFlag=false #26

meowtec opened this issue Aug 17, 2019 · 4 comments

Comments

@meowtec
Copy link

meowtec commented Aug 17, 2019

rewritePattern('hello.world', 'su', {
  dotAllFlag: false,
})
/hello.world/su.test('hello\nworld') 
// should output: true
/hello(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])world/s.test('hello\nworld'))
// but output: false
@JLHwung
Copy link
Collaborator

JLHwung commented Aug 17, 2019

It is expected. The dotAllFlag option enables the dotall-flag support.

rewritePattern('.', 's', {
  'dotAllFlag': true
});
// → '[\\0-\\uFFFF]'

@meowtec
Copy link
Author

meowtec commented Aug 17, 2019

@JLHwung I think

rewritePattern('hello.world', 'su', {
  dotAllFlag: false,
})

should get result like this:

(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])|.

(add |. at the end)

// so this will be true:
/(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])|./s
.test('\n') // true

@meowtec
Copy link
Author

meowtec commented Aug 17, 2019

Otherwise we should set dotAllFlag always to true(if has 's' flag) in proposal-unicode-property-regex because the '.' would lost before transform-dotall-regex.

@JLHwung
Copy link
Collaborator

JLHwung commented Aug 17, 2019

@meowtec Exactly, I proposed in babel/babel#10347 (comment) and we do have a workaround in hand.

This issue comes from how babel invokes regexpu-core, so I suggest discussion in babel/babel#10347 with the a babel plugin context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants