stealjs / steal

Gets JavaScript
https://stealjs.com
MIT License
1.36k stars 522 forks source link

ES classes in dependencies aren't transpiled #1505

Open nlundquist opened 5 years ago

nlundquist commented 5 years ago

Reproducible: Always

Description: When using native classes from an NPM dependency (e.g CanJS 6) they're not transpiled even though app modules are transpiled. This is an issue when the app modules include classes that extend the classes from an NPM dependency, e.g:

import ObservableObject from 'can-observable-object';
class Todo extends ObservableObject {
    ...
}
const todo = new Todo();

This will result in an error along the lines of: Uncaught TypeError: Class constructor Child cannot be invoked without 'new'

This is because the ObservableObject class is not transpiled, but the Todo class is transpiled and transpiled classes cannot extend native classes since transpiled classes try to call their base class like a function rather than invoking with new.

It's unclear what the correct solution to this problem is. Depending on the supported browsers for your app one solution may be to prevent class transpilation inside app modules. The other option would be to apply transpilations to NPM dependencies so all classes are transpiled. Both have downsides. Stopping transpilation limits browser support, increasing transpilation increases bundle size and increases dev mode transpilation delays.

matthewp commented 5 years ago

I think the bug here is the way ES classes are transpiled to constructor functions. They are not compatible with ES base classes.

matthewp commented 5 years ago

Otherwise #1276 is needed.

justinbmeyer commented 5 years ago

Could we just avoid classes in our code?

matthewp commented 5 years ago

That wouldn't solve this steal issue, no.

frank-dspeed commented 4 years ago

i have a way to handle that but i need some extra info is Steal's output formart still Systemjs loader compatible or lets say SystemJS compatible when systemjs gets loaded as Steal? @matthewp

matthewp commented 4 years ago

@frank-dspeed Sorry, I don't understand your question. can you rephrase?

frank-dspeed commented 4 years ago

Conclusion

as maybe some people know i am working on stuff like typescript rollup vscode.

As WebComponents Pollyfill is big and hugh It is more clever to transpil WebComponents into a other Formart like canjs-view-parser :D

The CanJS way is the most efficent and compatible that still exists. It is a WebComponents Pollyfill it self,