refactor(compiler): better constant hoist/stringify checks

This commit is contained in:
Evan You
2020-11-20 19:26:07 -05:00
parent acba86ef45
commit 90bdf59f4c
22 changed files with 291 additions and 204 deletions

View File

@@ -9,7 +9,8 @@ import {
NodeTypes,
Position,
TextNode,
InterpolationNode
InterpolationNode,
ConstantTypes
} from '../src/ast'
describe('compiler: parse', () => {
@@ -177,7 +178,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: `message`,
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
loc: {
start: { offset: 2, line: 1, column: 3 },
end: { offset: 9, line: 1, column: 10 },
@@ -202,7 +203,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: `a<b`,
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
loc: {
start: { offset: 3, line: 1, column: 4 },
end: { offset: 6, line: 1, column: 7 },
@@ -228,7 +229,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: `a<b`,
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
loc: {
start: { offset: 3, line: 1, column: 4 },
end: { offset: 6, line: 1, column: 7 },
@@ -247,7 +248,7 @@ describe('compiler: parse', () => {
content: {
type: NodeTypes.SIMPLE_EXPRESSION,
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
content: 'c>d',
loc: {
start: { offset: 12, line: 1, column: 13 },
@@ -273,8 +274,8 @@ describe('compiler: parse', () => {
content: {
type: NodeTypes.SIMPLE_EXPRESSION,
isStatic: false,
// The `isConstant` is the default value and will be determined in `transformExpression`.
isConstant: false,
// The `constType` is the default value and will be determined in `transformExpression`.
constType: ConstantTypes.NOT_CONSTANT,
content: '"</div>"',
loc: {
start: { offset: 8, line: 1, column: 9 },
@@ -303,7 +304,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: `msg`,
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
loc: {
start: { offset: 4, line: 1, column: 5 },
end: { offset: 7, line: 1, column: 8 },
@@ -1028,7 +1029,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'a',
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
loc: {
start: { offset: 11, line: 1, column: 12 },
end: { offset: 12, line: 1, column: 13 },
@@ -1054,7 +1055,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'click',
isStatic: true,
isConstant: true,
constType: ConstantTypes.CAN_STRINGIFY,
loc: {
source: 'click',
@@ -1091,7 +1092,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'event',
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
loc: {
source: '[event]',
@@ -1164,7 +1165,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'click',
isStatic: true,
isConstant: true,
constType: ConstantTypes.CAN_STRINGIFY,
loc: {
source: 'click',
@@ -1201,7 +1202,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'a.b',
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
loc: {
source: '[a.b]',
@@ -1238,7 +1239,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'a',
isStatic: true,
isConstant: true,
constType: ConstantTypes.CAN_STRINGIFY,
loc: {
source: 'a',
@@ -1259,7 +1260,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'b',
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
loc: {
start: { offset: 8, line: 1, column: 9 },
@@ -1286,7 +1287,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'a',
isStatic: true,
isConstant: true,
constType: ConstantTypes.CAN_STRINGIFY,
loc: {
source: 'a',
@@ -1307,7 +1308,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'b',
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
loc: {
start: { offset: 13, line: 1, column: 14 },
@@ -1334,7 +1335,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'a',
isStatic: true,
isConstant: true,
constType: ConstantTypes.CAN_STRINGIFY,
loc: {
source: 'a',
@@ -1355,7 +1356,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'b',
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
loc: {
start: { offset: 8, line: 1, column: 9 },
@@ -1382,7 +1383,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'a',
isStatic: true,
isConstant: true,
constType: ConstantTypes.CAN_STRINGIFY,
loc: {
source: 'a',
@@ -1403,7 +1404,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'b',
isStatic: false,
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
loc: {
start: { offset: 14, line: 1, column: 15 },
@@ -1430,7 +1431,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'a',
isStatic: true,
isConstant: true,
constType: ConstantTypes.CAN_STRINGIFY,
loc: {
source: 'a',
start: {
@@ -1450,8 +1451,8 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: '{ b }',
isStatic: false,
// The `isConstant` is the default value and will be determined in transformExpression
isConstant: false,
// The `constType` is the default value and will be determined in transformExpression
constType: ConstantTypes.NOT_CONSTANT,
loc: {
start: { offset: 10, line: 1, column: 11 },
end: { offset: 15, line: 1, column: 16 },
@@ -1478,7 +1479,7 @@ describe('compiler: parse', () => {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'foo.bar',
isStatic: true,
isConstant: true,
constType: ConstantTypes.CAN_STRINGIFY,
loc: {
source: 'foo.bar',
start: {