Skip to content

Commit

Permalink
feat: remove literalValue from attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Oct 13, 2021
1 parent eaf6327 commit a95b9f2
Show file tree
Hide file tree
Showing 23 changed files with 19 additions and 66 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,15 @@ OUTPUT EVENT:
attributes: [
{
name: 'class',
value: '"demo"',
literalValue: 'demo'
value: '"demo"'
},
{
name: 'disabled',
value: 'false',
literalValue: false
value: 'false'
},
{
name: 'data-number',
value: '123',
literalValue: 123
value: '123'
}
]
}
Expand Down
21 changes: 0 additions & 21 deletions src/states/ATTRIBUTE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,6 @@ export const ATTRIBUTE = Parser.createState({
attr.value = value;
attr.pos = childPart.pos;
attr.endPos = childPart.endPos;

// If the expression evaluates to a literal value then add the
// `literalValue` property to the attribute
if (childPart.isStringLiteral) {
attr.literalValue = evaluateStringExpression(
value,
childPart.pos,
this
);
} else if (value === "true") {
attr.literalValue = true;
} else if (value === "false") {
attr.literalValue = false;
} else if (value === "null") {
attr.literalValue = null;
} else if (value === "undefined") {
attr.literalValue = undefined;
} else if (NUMBER_REGEX.test(value)) {
attr.literalValue = Number(value);
}

this.exitState();
break;
}
Expand Down
4 changes: 0 additions & 4 deletions src/util/notify-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ export function createNotifiers(parser, listeners) {
bound: attr.bound,
};

if (attr.hasOwnProperty("literalValue")) {
(newAttr as any).literalValue = attr.literalValue;
}

return newAttr;
}),
setParseOptions(parseOptions) {
Expand Down
3 changes: 2 additions & 1 deletion test/autotest/attr-escaped-dollar/expected.html
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
undefined
<span data-foo=("\$name")>
</span>
5 changes: 0 additions & 5 deletions test/autotest/attr-escaped-dollar/test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/autotest/attr-literal-false/expected.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div data=(false)[Literal: false]>
<div data=(false)>
</div>
1 change: 0 additions & 1 deletion test/autotest/attr-literal-false/test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/autotest/attr-literal-null/expected.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div data=(null)[Literal: null]>
<div data=(null)>
</div>
1 change: 0 additions & 1 deletion test/autotest/attr-literal-null/test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/autotest/attr-literal-numbers/expected.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div data=(1)[Literal: 1] data=(.5)[Literal: 0.5] data=(1.5)[Literal: 1.5] data=(1.5e10)[Literal: 15000000000] data=(1.5e+10)[Literal: 15000000000] data=(1.5e-10)[Literal: 1.5e-10] data=(-1)[Literal: -1] data=(-.5)[Literal: -0.5] data=(-1.5)[Literal: -1.5] data=(-1.5e10)[Literal: -15000000000] data=(-1.5e+10)[Literal: -15000000000] data=(-1.5e-10)[Literal: -1.5e-10]>
<div data=(1) data=(.5) data=(1.5) data=(1.5e10) data=(1.5e+10) data=(1.5e-10) data=(-1) data=(-.5) data=(-1.5) data=(-1.5e10) data=(-1.5e+10) data=(-1.5e-10)>
</div>
1 change: 0 additions & 1 deletion test/autotest/attr-literal-numbers/test.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div class=("simple")[Literal: "simple"]>
<div class=("simple")>
</div>
1 change: 0 additions & 1 deletion test/autotest/attr-literal-string-double-quotes/test.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div class=('simple')[Literal: "simple"]>
<div class=('simple')>
</div>
1 change: 0 additions & 1 deletion test/autotest/attr-literal-string-single-quotes/test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/autotest/attr-literal-true/expected.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div data=(true)[Literal: true]>
<div data=(true)>
</div>
1 change: 0 additions & 1 deletion test/autotest/attr-literal-true/test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/autotest/attr-literal-undefined/expected.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div data=(undefined)[Literal: undefined]>
<div data=(undefined)>
</div>
1 change: 0 additions & 1 deletion test/autotest/attr-literal-undefined/test.js

This file was deleted.

4 changes: 2 additions & 2 deletions test/autotest/attr-non-literal/expected.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div data=(('a'))[Literal: (empty)] a=(a+b)[Literal: (empty)] b=('foo'+'bar')[Literal: (empty)] template-string=(`foo`)[Literal: (empty)]>
<div data=(('a')) a=(a+b) b=('foo'+'bar') template-string=(`foo`)>
</div>
text:"\n"
<span test=('123'"abc")[Literal: (empty)]>
<span test=('123'"abc")>
</span>
1 change: 0 additions & 1 deletion test/autotest/attr-non-literal/test.js

This file was deleted.

This file was deleted.

16 changes: 5 additions & 11 deletions test/util/TreeBuilder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
var expect = require('chai').expect;

function attributesToString(attributes, includeLiteralValues) {
function attributesToString(attributes) {
var len = attributes && attributes.length || 0;
if (!len) {
return '';
Expand All @@ -13,7 +13,7 @@ function attributesToString(attributes, includeLiteralValues) {

if (attr.default) {
i = 1;
result = " DEFAULT" + attributeAssignmentToString(attr, includeLiteralValues);
result = " DEFAULT" + attributeAssignmentToString(attr);
}

for (;i < len; i++) {
Expand All @@ -24,13 +24,13 @@ function attributesToString(attributes, includeLiteralValues) {
result += '(' + attr.argument.value + ')';
}

result += attributeAssignmentToString(attr, includeLiteralValues);
result += attributeAssignmentToString(attr);
}

return result;
}

function attributeAssignmentToString(attr, includeLiteralValues) {
function attributeAssignmentToString(attr) {
var result = "";

if (attr.value) {
Expand All @@ -43,10 +43,6 @@ function attributeAssignmentToString(attr, includeLiteralValues) {
result += '=(EMPTY)';
}

if (includeLiteralValues) {
result += '[Literal: ' + (attr.hasOwnProperty('literalValue') ? JSON.stringify(attr.literalValue) : '(empty)') + ']';
}

return result;
}

Expand Down Expand Up @@ -178,7 +174,7 @@ class ElementNode {
}).join(', ') + ']';
}

str += attributesToString(attributes, out.includeLiteralValues) + (openTagOnly ? ' OPEN_ONLY' : '') + (selfClosed ? ' SELF_CLOSED' : '') + '>';
str += attributesToString(attributes) + (openTagOnly ? ' OPEN_ONLY' : '') + (selfClosed ? ' SELF_CLOSED' : '') + '>';
out.writeLine(str);

out.incIndent();
Expand All @@ -200,7 +196,6 @@ class TreeBuilder {

this.src = src;
this.includePositions = options && options.includePositions === true;
this.includeLiteralValues = options && options.includeLiteralValues === true;
this.includeTextParserState = options.includeTextParserState === true;

this.root = new RootNode();
Expand Down Expand Up @@ -394,7 +389,6 @@ class TreeBuilder {
var buffer = '';
var out = {
includePositions: this.includePositions === true,
includeLiteralValues: this.includeLiteralValues === true,
includeTextParserState: this.includeTextParserState === true,
incIndent() {
indent += ' ';
Expand Down

0 comments on commit a95b9f2

Please sign in to comment.