Skip to content

Commit a65bcfc

Browse files
committed
fix
1 parent 5d642c1 commit a65bcfc

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

parser/bnf.js

+11-20
Original file line numberDiff line numberDiff line change
@@ -81,32 +81,23 @@ compiler.ParseScript = function (script) {
8181
const aqLiterals = []
8282
let _script = script
8383
let res = ''
84-
let qsMatch = _script.match(/^([^"]*)("([^"\\]|\\.)*")?/)
84+
const re = /^([^"`]*)("(([^"\\]|\\.)*)"|`(([^`\\]|\\.)*)`)?/
85+
let qsMatch = _script.match(re)
8586
while (qsMatch && qsMatch[0]) {
86-
let repl = qsMatch[2] || ''
87+
let repl = qsMatch[2] || qsMatch[4] || ''
8788
if (repl.length > 512) {
88-
qLiterals.push(repl)
89-
repl = `"QL_${qLiterals.length - 1}"`
89+
if (repl.startsWith('"')) {
90+
qLiterals.push(repl)
91+
repl = `"QL_${qLiterals.length - 1}"`
92+
} else {
93+
aqLiterals.push(repl)
94+
repl = `\`AL_${aqLiterals.length - 1}\``
95+
}
9096
}
9197
res = res + qsMatch[1] + repl
9298
_script = _script.slice(qsMatch[0].length)
93-
qsMatch = _script.match(/^([^"]*)("([^"\\]|\\.)*")?/)
99+
qsMatch = _script.match(re)
94100
}
95-
96-
_script = res
97-
res = ''
98-
qsMatch = _script.match(/^([^`]*)(`([^`\\]|\\.)*`)?/)
99-
while (qsMatch && qsMatch[0]) {
100-
let repl = qsMatch[2] || ''
101-
if (repl.length > 512) {
102-
aqLiterals.push(repl)
103-
repl = `\`AL_${qLiterals.length - 1}\``
104-
}
105-
res = res + qsMatch[1] + repl
106-
_script = _script.slice(qsMatch[0].length)
107-
qsMatch = _script.match(/^([^`]*)(`([^`\\]|\\.)*`)?/)
108-
}
109-
110101
const parsedScript = this._ParseScript(res)
111102
if (!parsedScript) {
112103
return parsedScript

parser/registry/common.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ module.exports.querySelectorPostProcess = (query) => {
8585
* @returns {string}
8686
*/
8787
module.exports.unquoteToken = (token) => {
88-
let value = token.Child('quoted_str').value
89-
value = `"${value.substr(1, value.length - 2)}"`
90-
return JSON.parse(value)
88+
const value = token.Child('quoted_str').value
89+
if (value.startsWith('"')) {
90+
return JSON.parse(value)
91+
}
92+
return value.substr(1, value.length - 2)
9193
}
9294

9395
/**

0 commit comments

Comments
 (0)