diff --git a/packages/import-cost/README.md b/packages/import-cost/README.md index a06d85c..9e172f8 100644 --- a/packages/import-cost/README.md +++ b/packages/import-cost/README.md @@ -33,7 +33,7 @@ Usage as you can see above is pretty straight forward, `importCost()` gets three 1) `fileName` - This is a `string` representing the full path to the file that is being processed. We need full file path since we need to look inside `node_modules` folder of the file in question 2) `fileContents` - This is a `string` which contains the actual content of the file. We need it because in IDE extension it is usually much faster to get contents from IDE then reading it from filesystem. Also, obviously changes to the file might not have been saved yet, we want to work on the file as the user types to it. -3) `language` - This effects which AST parser we will use to lookup the imports in the file. As you can see above, you pass either `Lang.JAVASCRIPT`, `Lang.TYPESCRIPT`, `Lang.VUE` or `Lang.SVELTE` to it. Typically IDE can tell you the language of the file, better use the correct API of your IDE then rely on extensions. +3) `language` - This effects which AST parser we will use to lookup the imports in the file. As you can see above, you pass either `Lang.JAVASCRIPT`, `Lang.TYPESCRIPT`, `Lang.VUE`, `Lang.SVELTE`, `Lang.GLIMMER_JS`, or `Lang.GLIMMER_TS` to it. Typically IDE can tell you the language of the file, better use the correct API of your IDE then rely on extensions. 4) `config` (optional) - Object containing the following keys: `maxCallTime` - give up after timeout (in milliseconds) if bundle calculation didn't complete, `concurrent` - boolean representing whether calculation should happen in multiple workers. In response, `importCost()` returns a standard Node `EventEmitter`. You can read about event emitters in [Node docs](https://nodejs.org/api/events.html#events_class_eventemitter), but typically all you need to know is that you can register a callback for various events we emit using `emitter.on(eventName, callback)`. We also recommend you un-register using `emitter.removeAllListeners()` when the file in question changes, this will help you not be confused with any results that are no longer relevant to that file. diff --git a/packages/import-cost/src/langs.js b/packages/import-cost/src/langs.js index b3494c1..34cb6f1 100644 --- a/packages/import-cost/src/langs.js +++ b/packages/import-cost/src/langs.js @@ -3,6 +3,8 @@ const Lang = { JAVASCRIPT: 'javascript', VUE: 'vue', SVELTE: 'svelte', + GLIMMER_JS: 'glimmer-js', + GLIMMER_TS: 'glimmer-ts', }; module.exports = { diff --git a/packages/import-cost/src/parser.js b/packages/import-cost/src/parser.js index 8673242..3960b82 100644 --- a/packages/import-cost/src/parser.js +++ b/packages/import-cost/src/parser.js @@ -23,8 +23,23 @@ function getScriptTagLineNumber(html) { return 0; } +function stripTemplateTag(source) { + // Replace all template tags within an assignment expression or a return to a no-op + let sourceStripped = source.replace( + /(=|return)\s*?