我需要为nullish-coalescing-operator和optional-chaining进行填充。

huangapple go评论55阅读模式
英文:

I need to polyfill nullish-coalescing-operator and optional-chaining

问题

I have an angular application which I recently upgraded to angular 15. I have a requirement to support it in Chrome 69 browser. When I run in Chrome 69, I get 2 errors which are related to the optional-chaining and nullish-coalescing-operator.

Could someone tell me what I need to add to my polyfills.ts file to support these operators in Chrome 69. I know babel has some plugins to support this and we can polyfill using it, but I don't want to use Babel unless it is the only option. Can I do it using core-js?

I tried the adding following lines in my polyfills.ts file:

import 'core-js/features/nullish-coalescing-operator';
import 'core-js/features/optional-chaining';

But, my code doesn't compile. I get the below error:

Error: Module not found: Error: Can't resolve 'core-js/features/nullish-coalescing-operator'
Error: Module not found: Error: Can't resolve 'core-js/features/optional-chaining'

Any help would be appreciated. Thanks in Advance!!

Edit:
As per the core-js official documentation link I can use core-js for polyfills instead of @babel/polyfill. I already have the below 2 lines in my polyfills.ts file

import 'core-js/stable';
import 'regenerator-runtime/runtime';

Please let me know what else I need to add support for nullish-coalescing-operator and optional-chaining?

英文:

I have an angular application which I recently upgraded to angular 15. I have a requirement to support it in Chrome 69 browser. When I run in Chrome 69, I get 2 errors which are related to the optional-chaining and nullish-coalescing-operator.

Could someone tell me what I need to add to my polyfills.ts file to support these operators in Chrome 69. I know babel has some plugins to support this and we can polyfill using it, but I don't want to use Babel unless it is the only option. Can I do it using core-js?

I tried the adding following lines in my polyfills.ts file:

import 'core-js/features/nullish-coalescing-operator';
import 'core-js/features/optional-chaining';

But, my code doesn't compile. I get the below error:

 Error: Module not found: Error: Can't resolve 'core-js/features/nullish-coalescing-operator'
 Error: Module not found: Error: Can't resolve 'core-js/features/optional-chaining'

Any help would be appreciated. Thanks in Advance!!

Edit:
As per the core-js official documentation https://github.com/zloirock/core-js#babelpolyfill I can use core-js for polyfills instead of @babel/polyfill. I already have the below 2 lines in my polyfills.ts file

import 'core-js/stable';
import 'regenerator-runtime/runtime';

Please let me know what else I need to add support for nullish-coalescing-operator and optional-chaining?

答案1

得分: 1

这些补丁在 core-js 中不存在。

此外,这不能作为两者都是语法糖的 polyfill。Babel 不是 polyfill,而是 transpile。

英文:

These patches don't exist in core-js.

More over, this can't be polyfiled as both are syntactic sugar. Babel isn't polyfilling but transpiling.

huangapple
  • 本文由 发表于 2023年6月8日 03:18:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76426475.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定