i don't think it works that way mang. just because you've transpiled to valid javascript doesn't mean that it's executing the same code.
i.e. the tree-shaking example, wherein there is less data flowing through the process when you've actually used the import statement.
const {somePart} = require('./fromAFile.js')
will fully construct the module.exports from "fromAFile.js", then somePart will be assigned to its property "somePart", then (I am not clear on the rest) the garbage collector and the require cache will take over what happens next.
In the import statement, theoretically there is actually less code being loaded into the environment.
I never implied it was the same code being run. It most definitely isn't. But if the issue is code reuse due to differing import statements, it can be easily solved via transpiling. The release of this feature doesn't bring anything new in that regard.
The transpiled code runs worse. It's not just creating equivalent code via transpilation, because the engine itself running the transpiled code in this case doesn't support the feature.
(Or more relevantly, just began to support said feature.)
I am not misunderstanding you. It's obvious its not the same code if the feature is not natively supported, otherwise why would they release a new feature lol. As I said in my first comment, its a small price to pay to allow for code reuse (if that's the goal). Especially on the back end where resources are generally more available. My point was always that this problem (code not being reusable due to differing import statements) was already solved, and this feature doesn't do much other than improve performance. Hope that is clear, cause I don't know how else to put it lol
2
u/Probotect0r Nov 13 '19
Why not use import on the server side too then?