Add preprocessEmbeddedTemplates
function
#361
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a function for preprocessing embedded templates. This function finds embedded templates using a simple RegExp + stack based parser which is very limited overall and designed specifically for this purpose. It replaces the embedded templates with parseable JS, and also pre-parses and walks the templates to find all possible identifiers within them and exposes them externally:
Becomes:
The preprocessor does not understand the surrounding JS scope and so does not know if the identifiers it emits actually exist in scope and are valid (it will only emit valid JS identifiers, however). So, if the preprocessed output is going to be used by another tool, such as a linter, it's up to the user to postprocess the results and remove errors pertaining to this generated code.
The result also includes a list of
replacements
which let the user know what was replaced in the original template, useful for fixing linting failure locations and so on. Also, it can include and handle sourcemaps.