Skip to content

Commit

Permalink
Add comments describing what the pre/post processor functions do
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli authored and nlfurniss committed Oct 25, 2022
1 parent 520cc63 commit 3b73b06
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/preprocessors/glimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ const util = require('ember-template-imports/src/util');
const TRANSFORM_CACHE = new Map();
const TEXT_CACHE = new Map();

/**
* This function is responsible for running the embedded templates transform
* from ember-template-imports.
*
* It takes a gjs or gts file and converts <template> tags to their
* intermediary (private) format.
*
* This is needed so that eslint knows what variables accessed within the template
* are missing or accessed within the JS scope, because
* part of the output includes a snippet that looks like:
*
* `, { strictMode: true, scope: () => ({on,noop}) })]
*
* So if on and noop are not present in the JS, we will have an error to work with
*/
function gjs(text, filename) {
const isGlimmerFile = filename.endsWith('.gjs') || filename.endsWith('.gts');

Expand All @@ -21,6 +36,11 @@ function gjs(text, filename) {
];
}

/**
* If the file is already processed, we don't need to process it again.
*
* a file will not have a TEMPLATE_TAG_PLACEHOLDER unless it has been processed
*/
if (text.includes(util.TEMPLATE_TAG_PLACEHOLDER)) {
return [
{
Expand Down Expand Up @@ -61,6 +81,12 @@ function gjs(text, filename) {
];
}

/**
* This function is for mapping back from the intermediary (private) format
* back to gjs/gts / <template> so that we can appropriatly display errors
* or warnings in the correct location in the original source file in the user's
* editor.
*/
function mapRange(messages, filename) {
const transformed = TRANSFORM_CACHE.get(filename);
const original = TEXT_CACHE.get(filename);
Expand Down

0 comments on commit 3b73b06

Please sign in to comment.