Skip to content

PR: 7.0 - ESM - Only version  #330

@frank-dspeed

Description

@frank-dspeed

As NodeJS LTS Now Reached the state where ESM Works and we got a 100% Way to shim it for older NodeJS Versions it
is time to Refactor this to ESM Only which would directly run Inside Nodejs & WebBrowsers

Issus to Tackle in this Major

Old Issue that got noisy and out of topic discussions

TODO

  • Update Documentation
  • Drop use of class, this, null
  • Switch to Functional Composition and drop Mixins
  • Get TypeScript Happy with JSDOC Comments.
  • Create new Tests that are Working in NodeJS and the Brwoser.
  • Current Extension Model Replacement
    • Static Analyzeable Classes that do clear extend each other for all 3 situations Raw/with error/with sourcecode info
    • Functional Composition
    • Event Emitter Pattern

5th iteration conclusions

Findings:
The Result of new Parser() should get wrapped when extending the parser it is not so easy to follow the inharitance of objects with
the self written Mixin Class system that offers a later install method which will patch a eventual existing _bootstrap method that later
gets eventual called when using Parser.parse or Parser.parseFragment.

All extensions should be written as proxy the treeAdapter should be named NodeAdapter is it is not forming the tree out of browser view
it is a Node api so we should express it like that to make more clear for other developers that there is the place to manipulate Node
Creation and handling. Proxy support starts with Nodejs 6.4 shim https://github.com/GoogleChrome/proxy-polyfill/blob/master/src/proxy.js

  • v8 JSONParse Optimization https://v8.dev/blog/cost-of-javascript-2019
  • treeAdapter should get replaced by a new Node() hireOrderFunction.
  • ErrorProxyHandler.applyl(target,thisArg, args) where target is Parser,Tokenizer,OpenElementStack, Preprocessor).
  • srcCodeLocationInfo.apply(...) where target is Tokenizer and Preprocessor
  • debuggingProxy as new feature that logs propertys.
  • Object.create(null) replaced by {}
  • Optional Propertys should not get null assigned
  • While Class is a nice form of representation out of coder view it needs to get avoided because of security problems with this
    • The Clossest Solution would be a hireOrderFunction that gets a shared state passed so that both sides of the code can operate
      on the same sharedState Object that got passed to the hireOrderFunction
  • toImprove loading speed it would be preferable to apply the v8 JSONParse Optimization at last in production
  • the entietieMap data should get transformed from .json to .js to be import able in the browser and in nodejs
  • add additional types.js file that exports the JSDOC Comments so can be treeshaken. and TypeScript config.
    • generate .d.ts files if possible maybe (It is not needed but needs rethinking as there is not standard) TypeScript will find the import and it gets treeShaken away or typescript looksup the .d.ts file by its algo and the file does not get bundled
      I Think .js JSDOC import is better as it supports to even bundle the TypeDefintions)
  • drop mixin implementation first version should be directly a higherOrderFunction that takes sharedState so drop class we start with preprocessor
  • drop option-merge we got Object.assign and ...{}

8ef28cd
Lexer implementation started. 0.6.1 … master v6.0.1 Ivan Nikulin committed on 15 Mar 2013

Why ESM Only?

my final Way to go will be a ESM only version this can then get transpiled via babel to cjs or with anything else.

Then the ESM version gets released as new Major version and can get used with current NodeJS via import() inside CJS

the README will show instructions to create a CJS version if needed. And it will point out that this new Major Version is Only ESM and to use it you will need NodeJS Version > 9.7.x or the npm esm package.

What do you think about it?

Browser ESM Support

NodeJS ESM Support

  • NodeJS 13.2+ .use import or import()
  • NodeJS 9.7+ use --experimental-modules then use import or import()
  • NodeJS 6+ use "npm install esm" then use import or import()
  • With TypeScript or with node-ts you can use it inside .ts files.
  • Most other Environments like Current Browsers and Deno or GraalJS will also work out of the box

NodeJS & BrowserProxy Support

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions