From ca9f87f047313448fa2a7984b7282fad51e99853 Mon Sep 17 00:00:00 2001 From: Saurabh Daware Date: Sun, 14 Mar 2021 19:24:40 +0530 Subject: [PATCH] fix(component-parser.js): fix scopedSelector being redefined on delayed callbacks like setTimeout (#44) * fix(component-parser.js): parse scopedSelector to document.querySelector on build * bump to 0.4.2 --- .gitignore | 2 +- .npmignore | 2 +- package.json | 2 +- src/parsers/component-parser.js | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b8fabf8..6778dbb 100644 --- a/.gitignore +++ b/.gitignore @@ -105,5 +105,5 @@ out.html .tern-port # playground of vm module -vm.playground.js +playground.js srcold/ \ No newline at end of file diff --git a/.npmignore b/.npmignore index 6e8c58e..c47f67a 100644 --- a/.npmignore +++ b/.npmignore @@ -5,5 +5,5 @@ examples/ .eslintignore .prettierrc .prettierignore -vm.playground.js +playground.js .vscode/ \ No newline at end of file diff --git a/package.json b/package.json index b6d1f12..fc31e6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "abell-renderer", - "version": "0.4.1", + "version": "0.4.2", "description": "JavaScript based Template Engine. Compiles .abell files to .html", "main": "src/index.js", "bin": { diff --git a/src/parsers/component-parser.js b/src/parsers/component-parser.js index ba0c5b0..2e10fd3 100644 --- a/src/parsers/component-parser.js +++ b/src/parsers/component-parser.js @@ -172,10 +172,10 @@ function parseComponent( } else if (!isCss && contentMatch[2].includes('scopedSelector')) { // if it is javascript then scope it by injecting scopedSelector functions // prettier-ignore - content = - `scopedSelector = (queryString) => document.querySelector(queryString + '[data-abell-${componentHash}]');` + // eslint-disable-line max-len - `scopedSelectorAll = (queryString) => document.querySelectorAll(queryString + '[data-abell-${componentHash}]');` // eslint-disable-line max-len - + contentMatch[2]; + content = contentMatch[2].replace( + /scoped(Selector|SelectorAll)\((['"`].*?["'`])\)/g, + `document.query$1($2 + "[data-abell-${componentHash}]")` + ); } else { content = contentMatch[2]; }