Skip to content

Commit

Permalink
feat: improvements to ERB template recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
revelt committed Feb 3, 2021
1 parent 9aeddc3 commit 5fd2ba1
Show file tree
Hide file tree
Showing 8 changed files with 598 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/codsen-tokenizer/coverage/coverage-summary.json
@@ -1 +1 @@
{"total":{"lines":{"total":855,"covered":789,"skipped":0,"pct":92.28},"statements":{"total":883,"covered":815,"skipped":0,"pct":92.3},"functions":{"total":42,"covered":40,"skipped":0,"pct":95.24},"branches":{"total":1351,"covered":1238,"skipped":0,"pct":91.64}}}
{"total":{"lines":{"total":855,"covered":789,"skipped":0,"pct":92.28},"statements":{"total":883,"covered":815,"skipped":0,"pct":92.3},"functions":{"total":42,"covered":40,"skipped":0,"pct":95.24},"branches":{"total":1355,"covered":1242,"skipped":0,"pct":91.66}}}
10 changes: 4 additions & 6 deletions packages/codsen-tokenizer/dist/codsen-tokenizer.cjs.js
Expand Up @@ -353,12 +353,10 @@ function matchLayerLast(wholeEspTagLump, layers, matchFirstInstead) {
// present in the extracted lump
Array.from(wholeEspTagLump).every(function (char) {
return whichLayerToMatch.guessedClosingLump.includes(char);
})) {
// console.log(
// `047 matchLayer(): ${`\u001b[${32}m${`RETURN`}\u001b[${39}m`} ${
// wholeEspTagLump.length
// }`
// );
}) || // consider ruby heads, <%# and tails -%>
whichLayerToMatch.guessedClosingLump && // length is more than 2
whichLayerToMatch.guessedClosingLump.length > 2 && // and last two characters match to what was guessed
whichLayerToMatch.guessedClosingLump[whichLayerToMatch.guessedClosingLump.length - 1] === wholeEspTagLump[wholeEspTagLump.length - 1] && whichLayerToMatch.guessedClosingLump[whichLayerToMatch.guessedClosingLump.length - 2] === wholeEspTagLump[wholeEspTagLump.length - 2]) {
return wholeEspTagLump.length;
} // console.log(`054 matchLayer(): finally, return undefined`);

Expand Down
10 changes: 4 additions & 6 deletions packages/codsen-tokenizer/dist/codsen-tokenizer.dev.umd.js
Expand Up @@ -3759,12 +3759,10 @@ function matchLayerLast(wholeEspTagLump, layers, matchFirstInstead) {
// present in the extracted lump
Array.from(wholeEspTagLump).every(function (char) {
return whichLayerToMatch.guessedClosingLump.includes(char);
})) {
// console.log(
// `047 matchLayer(): ${`\u001b[${32}m${`RETURN`}\u001b[${39}m`} ${
// wholeEspTagLump.length
// }`
// );
}) || // consider ruby heads, <%# and tails -%>
whichLayerToMatch.guessedClosingLump && // length is more than 2
whichLayerToMatch.guessedClosingLump.length > 2 && // and last two characters match to what was guessed
whichLayerToMatch.guessedClosingLump[whichLayerToMatch.guessedClosingLump.length - 1] === wholeEspTagLump[wholeEspTagLump.length - 1] && whichLayerToMatch.guessedClosingLump[whichLayerToMatch.guessedClosingLump.length - 2] === wholeEspTagLump[wholeEspTagLump.length - 2]) {
return wholeEspTagLump.length;
} // console.log(`054 matchLayer(): finally, return undefined`);

Expand Down
10 changes: 4 additions & 6 deletions packages/codsen-tokenizer/dist/codsen-tokenizer.esm.js
Expand Up @@ -327,12 +327,10 @@ function matchLayerLast(wholeEspTagLump, layers, matchFirstInstead = false) {
if ( // imagine case of Nunjucks: heads "{%" are normal but tails "-%}" (notice dash)
wholeEspTagLump.includes(whichLayerToMatch.guessedClosingLump) || // match every character from the last "layers" complex-type entry must be
// present in the extracted lump
Array.from(wholeEspTagLump).every(char => whichLayerToMatch.guessedClosingLump.includes(char))) {
// console.log(
// `047 matchLayer(): ${`\u001b[${32}m${`RETURN`}\u001b[${39}m`} ${
// wholeEspTagLump.length
// }`
// );
Array.from(wholeEspTagLump).every(char => whichLayerToMatch.guessedClosingLump.includes(char)) || // consider ruby heads, <%# and tails -%>
whichLayerToMatch.guessedClosingLump && // length is more than 2
whichLayerToMatch.guessedClosingLump.length > 2 && // and last two characters match to what was guessed
whichLayerToMatch.guessedClosingLump[whichLayerToMatch.guessedClosingLump.length - 1] === wholeEspTagLump[wholeEspTagLump.length - 1] && whichLayerToMatch.guessedClosingLump[whichLayerToMatch.guessedClosingLump.length - 2] === wholeEspTagLump[wholeEspTagLump.length - 2]) {
return wholeEspTagLump.length;
} // console.log(`054 matchLayer(): finally, return undefined`);

Expand Down
2 changes: 1 addition & 1 deletion packages/codsen-tokenizer/dist/codsen-tokenizer.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/codsen-tokenizer/dist/codsen-tokenizer.umd.js

Large diffs are not rendered by default.

23 changes: 17 additions & 6 deletions packages/codsen-tokenizer/src/util/matchLayerLast.ts
Expand Up @@ -47,13 +47,24 @@ function matchLayerLast(
// present in the extracted lump
Array.from(wholeEspTagLump).every((char) =>
whichLayerToMatch.guessedClosingLump.includes(char)
)
) ||
// consider ruby heads, <%# and tails -%>
(whichLayerToMatch.guessedClosingLump &&
// length is more than 2
whichLayerToMatch.guessedClosingLump.length > 2 &&
// and last two characters match to what was guessed
whichLayerToMatch.guessedClosingLump[
whichLayerToMatch.guessedClosingLump.length - 1
] === wholeEspTagLump[wholeEspTagLump.length - 1] &&
whichLayerToMatch.guessedClosingLump[
whichLayerToMatch.guessedClosingLump.length - 2
] === wholeEspTagLump[wholeEspTagLump.length - 2])
) {
// console.log(
// `047 matchLayer(): ${`\u001b[${32}m${`RETURN`}\u001b[${39}m`} ${
// wholeEspTagLump.length
// }`
// );
console.log(
`047 matchLayer(): ${`\u001b[${32}m${`RETURN`}\u001b[${39}m`} ${
wholeEspTagLump.length
}`
);
return wholeEspTagLump.length;
}

Expand Down

0 comments on commit 5fd2ba1

Please sign in to comment.