angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

npm run build generates broken regular expressions

Open novathore opened this issue 4 years ago • 5 comments

🐞 Bug report

  • [ ] new
  • [x] build
  • [ ] serve
  • [ ] test
  • [ ] e2e
  • [ ] generate
  • [ ] add
  • [ ] update
  • [ ] lint
  • [ ] extract-i18n
  • [ ] run
  • [ ] config
  • [ ] help
  • [ ] version
  • [ ] doc

Is this a regression?

Yes, the previous version in which this bug was not present was: 12.1.3

In version 12.2 and above bug exists.

Description

npm run build generates broken regular expression. The source reg. expression and transpiled produce difference result.


sourceRegexp = /(^|[^а-яё])([☎☏✆📠📞📱]|т\.|тел\.|ф\.|моб\.|факс|сотовый|мобильный|телефон)(:?\s*?)([+\d(][\d \u00A0\-()]{3,}\d)/gi

transpiledRegexp = /(^|[^\u0430-\u044f\u0451])([\u260e\u260f\u2706\u{1f4e0}\u{1f4de}\u{1f4f1}]|\u0442\.|\u0442\u0435\u043b\.|\u0444\.|\u043c\u043e\u0431\.|\u0444\u0430\u043a\u0441|\u0441\u043e\u0442\u043e\u0432\u044b\u0439|\u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0439|\u0442\u0435\u043b\u0435\u0444\u043e\u043d)(:?\s*?)([+\d(][\d \u00A0\-()]{3,}\d)/gi

sourceRegexp.test('111111') ->> false

transpiledRegexp.test('111111') ->> true

In version 12.1.3, npm run build transpiled source regexp to:


/(^|[^\u0430-\u044f\u0451])([\u260e\u260f\u2706\ud83d\udce0\ud83d\udcde\ud83d\udcf1]|\u0442\.|\u0442\u0435\u043b\.|\u0444\.|\u043c\u043e\u0431\.|\u0444\u0430\u043a\u0441|\u0441\u043e\u0442\u043e\u0432\u044b\u0439|\u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0439|\u0442\u0435\u043b\u0435\u0444\u043e\u043d)(:?\s*?)([+\d(][\d \u00A0\-()]{3,}\d)/gi;

🔬 Minimal Reproduction

https://github.com/novathore/angular-cli-regexp

  1. git clone [email protected]:novathore/angular-cli-regexp.git
  2. npm run build
  3. check main.js for variable regExp

🌍 Your Environment


Angular CLI: 13.2.3
Node: 16.13.2
Package Manager: npm 8.1.2
OS: darwin x64

Angular: 13.2.2
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1302.3
@angular-devkit/build-angular   13.2.3
@angular-devkit/core            13.2.3
@angular-devkit/schematics      13.2.3
@angular/cli                    13.2.3
@schematics/angular             13.2.3
rxjs                            7.5.4
typescript                      4.5.5

novathore avatar Feb 14 '22 12:02 novathore

Hi @novathore,

Unfortunately, this seems to be an issue with terser.

console.log(/(^|[^а-яё])([☎☏✆📠📞📱]|т\.|тел\.|ф\.|моб\.|факс|сотовый|мобильный|телефон)(:?\s*?)([+\d(][\d \u00A0\-()]{3,}\d)/gi)
npx terser index.js --format ascii_only --ecma=2017
console.log(/(^|[^\u0430-\u044f\u0451])([\u260e\u260f\u2706\u{1f4e0}\u{1f4de}\u{1f4f1}]|\u0442\.|\u0442\u0435\u043b\.|\u0444\.|\u043c\u043e\u0431\.|\u0444\u0430\u043a\u0441|\u0441\u043e\u0442\u043e\u0432\u044b\u0439|\u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0439|\u0442\u0435\u043b\u0435\u0444\u043e\u043d)(:?\s*?)([+\d(][\d \u00A0\-()]{3,}\d)/gi);

Please contact the author(s) of the terser or file an issue on their issue tracker.

alan-agius4 avatar Feb 14 '22 14:02 alan-agius4

@clydin correctly pointed that as a workaround you can add the /u modifier for unicode support.

alan-agius4 avatar Feb 14 '22 15:02 alan-agius4

@alan-agius4 terser just released new version with regex fix https://github.com/terser/terser/blob/master/CHANGELOG.md#v5110 can we update it for ng 13.2.x?

artaommahe avatar Feb 22 '22 08:02 artaommahe

@artaommahe: https://github.com/angular/angular-cli/pull/22745

alan-agius4 avatar Feb 22 '22 10:02 alan-agius4

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.