Skip to content

Commit e6c00e9

Browse files
Fix integer/string conversion when string is empty
1 parent 6a98c46 commit e6c00e9

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/ast.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ function replaceVariable(elem, variables, functionArgs, forceVariableAsString, e
3535
if (associatedValue instanceof Element) {
3636
// Nothing to be done in here.
3737
return associatedValue;
38-
} else if (['number', 'string', 'boolean'].includes(typeof associatedValue)) {
39-
if (typeof associatedValue === 'boolean') {
40-
return new IdentElement(
41-
associatedValue.toString(), startPos, endPos, lineNumber);
42-
} else if (typeof associatedValue === 'number' ||
43-
// eslint-disable-next-line no-extra-parens
44-
(!forceVariableAsString && matchInteger(associatedValue) === true)) {
45-
return new NumberElement(associatedValue, startPos, endPos, lineNumber);
46-
}
38+
} else if (typeof associatedValue === 'boolean') {
39+
return new IdentElement(
40+
associatedValue.toString(), startPos, endPos, lineNumber);
41+
} else if (typeof associatedValue === 'number' ||
42+
// eslint-disable-next-line no-extra-parens
43+
(!forceVariableAsString && matchInteger(associatedValue) === true)) {
44+
return new NumberElement(associatedValue, startPos, endPos, lineNumber);
45+
} else if (typeof associatedValue === 'string') {
4746
return new StringElement(
4847
associatedValue,
4948
startPos,

src/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function isLetter(c) {
2121
function matchInteger(s) {
2222
if (typeof s === 'number' || s instanceof Number) {
2323
return true;
24-
} else if (typeof s === 'string' || s instanceof String) {
24+
} else if ((typeof s === 'string' || s instanceof String) && s.length !== 0) {
2525
for (let i = s.length - 1; i >= 0; --i) {
2626
if (!isNumber(s.charAt(i))) {
2727
return false;

0 commit comments

Comments
 (0)