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

Some unsupported code with es2015 target set #22270

Closed
SetoKaiba opened this issue Dec 1, 2021 · 13 comments · Fixed by #22305
Closed

Some unsupported code with es2015 target set #22270

SetoKaiba opened this issue Dec 1, 2021 · 13 comments · Fixed by #22305

Comments

@SetoKaiba
Copy link

Which @angular/* package(s) are the source of the bug?

common

Is this a regression?

No

Description

image
This is not supported for es2015. But it's still there after compile. I'm trying to write a webpage for OBS studio. The ?. is not supported I think. And I think it's not in es2015 as well.
image
Here is the tsconfig. Set target to es2015 doesn't help. But the unsupported is gone if I set target to es5.
https://github.com/angular/angular/blob/b5ab7aff433a67cddaa55e621d17b1a1b07b57c2/packages/common/src/location/location_strategy.ts#L176-L178
Why this ?. is kept even I set target to es2015?

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

No response

Anything else?

No response

@JoostK
Copy link
Member

JoostK commented Dec 1, 2021

The occurrence of ?. exists in library code, which has already been compiled to JS. Therefore, the target option of your TypeScript compilation is irrelevant.

I'm afraid that without more insight into your building process, we'd be unable to help you. Please share a reproduction.

@SetoKaiba
Copy link
Author

@JoostK Just create an empty project with angular cli 13.0.3. Change the tsconfig.json target to es2015. ng serve. You will see the problematic code in vendor.js:8571.

@JoostK
Copy link
Member

JoostK commented Dec 1, 2021

What version of Chrome are you using?

@SetoKaiba
Copy link
Author

@JoostK If I change the target to es5, the problem gone. If it's a compiled library code, why?

image
I'm using the OBS studio with browser source. So I don't know what's the version of chrome it used.

image
And this is the remote debug for OBS studio browser. That's why I can find out the ?. is not supported.

I supposed ?. is a feature introduced in es10(2019).

@SetoKaiba
Copy link
Author

image
If I change the target to es5, the problem gone.
image

@JoostK JoostK transferred this issue from angular/angular Dec 1, 2021
@JoostK
Copy link
Member

JoostK commented Dec 1, 2021

The optional chaining support landed in Chrome 80, quite a while ago. Angular only supports the latest major of Chrome; if OBS is using an outdated version then Angular apps may break in unexpected ways.

The CLI has some heuristics to determine the output format to generate. It looks like it treats es5 targets differently than es2015. @alan-agius4 probably knows more about this, the output format of libraries might also depend on the browserslist configuration.

@alan-agius4
Copy link
Collaborator

In case the target is ES2019 or lower we should favour the FESM2015 entry-point.

@thw0rted
Copy link

thw0rted commented Dec 2, 2021

I don't have a horse in the race, but I am curious. If Angular only supports the latest major Chrome release, why do they still distribute / compile to (optionally) downleveled code?

@SetoKaiba
Copy link
Author

Agreed. Angular should be a general web development platform for all users instead of latest chrome users.

@JoostK
Copy link
Member

JoostK commented Dec 2, 2021

Sorry, my comment was ambiguous: I didn't mean to say that only Chrome is supported, I meant say that specifically for Chrome we only support the latest major. That means that we test against it to verify that things work, it doesn't mean that we're actively breaking older versions (except for IE11, for which support was dropped in Angular 13)

@thw0rted
Copy link

thw0rted commented Dec 2, 2021

Ah, that makes more sense. So, are the "heuristics" the CLI uses to choose which packaging to use documented somewhere public-facing? I've always been kind of curious about the console output I see during a build, "Compiling @angular/core : es2015 as esm2015" etc.

@alan-agius4 alan-agius4 self-assigned this Dec 2, 2021
alan-agius4 added a commit that referenced this issue Dec 8, 2021
…plication targets ES2019 or lower

Previously, we always consumed the ES2020 entrypoints, which caused issues in environments where the application compilation target is ES2019 or lower and ES2020 is not supported.

This is because we only downlevel code when we target ES5 or below.

- ES5 or below compilations, ES2015 entrypoints are used and their code is downlevelled to ES5.
- ES2019 or below, ES2015 entrypoints are used and no downlevelling is involved.
- ES2020 or later, ES2020 entrypoints are used.

Closes #22270
alan-agius4 added a commit that referenced this issue Dec 8, 2021
…plication targets ES2019 or lower

Previously, we always consumed the ES2020 entrypoints, which caused issues in environments where the application compilation target is ES2019 or lower and ES2020 is not supported.

This is because we only downlevel code when we target ES5 or below.

- ES5 or below compilations, ES2015 entrypoints are used and their code is downlevelled to ES5.
- ES2019 or below, ES2015 entrypoints are used and no downlevelling is involved.
- ES2020 or later, ES2020 entrypoints are used.

Closes #22270
@danilmoro3
Copy link

danilmoro3 commented Dec 29, 2021

@alan-agius4
It doesn't work
"target": "es2015" in tsconfig.json still generate ESM2020 module with .mjs files

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants