mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fix regression in parse javascript not aborting on unrecognized nodes (#1184)
* Fix regression in parse javascript not aborting on unrecognized nodes
This commit is contained in:
parent
ca859cfdd5
commit
3338fd4e0a
@ -216,6 +216,8 @@ function parseExpression(src, builder, isExpression) {
|
||||
let convertedChild = convert(child);
|
||||
if (convertedChild) {
|
||||
container.appendChild(convertedChild);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return container;
|
||||
@ -319,11 +321,14 @@ function parseExpression(src, builder, isExpression) {
|
||||
return builder.vars(declarations, kind);
|
||||
}
|
||||
case "IfStatement": {
|
||||
const ifNode = builder.ifStatement(
|
||||
convert(node.test),
|
||||
convert(node.consequent)
|
||||
);
|
||||
const ifNodeTest = convert(node.test);
|
||||
const ifNodeBody = convert(node.consequent);
|
||||
|
||||
if (!ifNodeTest || !ifNodeBody) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const ifNode = builder.ifStatement(ifNodeTest, ifNodeBody);
|
||||
let alternate = node.alternate;
|
||||
|
||||
if (!alternate) {
|
||||
@ -334,32 +339,68 @@ function parseExpression(src, builder, isExpression) {
|
||||
container.appendChild(ifNode);
|
||||
|
||||
do {
|
||||
container.appendChild(
|
||||
alternate.consequent
|
||||
? builder.elseIfStatement(
|
||||
convert(alternate.test),
|
||||
convert(alternate.consequent)
|
||||
)
|
||||
: builder.elseStatement(convert(alternate))
|
||||
);
|
||||
if (alternate.consequent) {
|
||||
const elseIfNodeTest = convert(alternate.test);
|
||||
const elseIfNodeBody = convert(alternate.consequent);
|
||||
|
||||
if (!elseIfNodeTest || !elseIfNodeBody) {
|
||||
return null;
|
||||
}
|
||||
|
||||
container.appendChild(
|
||||
builder.elseIfStatement(
|
||||
elseIfNodeTest,
|
||||
elseIfNodeBody
|
||||
)
|
||||
);
|
||||
} else {
|
||||
const elseNodeBody = convert(alternate);
|
||||
|
||||
if (!elseNodeBody) {
|
||||
return null;
|
||||
}
|
||||
|
||||
container.appendChild(
|
||||
builder.elseStatement(elseNodeBody)
|
||||
);
|
||||
}
|
||||
|
||||
alternate = alternate.alternate;
|
||||
} while (alternate);
|
||||
|
||||
return container;
|
||||
}
|
||||
case "ForStatement": {
|
||||
const forNodeInit = convert(node.init);
|
||||
const forNodeTest = convert(node.test);
|
||||
const forNodeUpdate = convert(node.update);
|
||||
const forNodeBody = convert(node.body);
|
||||
|
||||
if (
|
||||
!forNodeInit ||
|
||||
!forNodeTest ||
|
||||
!forNodeUpdate ||
|
||||
!forNodeBody
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return builder.forStatement(
|
||||
convert(node.init),
|
||||
convert(node.test),
|
||||
convert(node.update),
|
||||
convert(node.body)
|
||||
forNodeInit,
|
||||
forNodeTest,
|
||||
forNodeUpdate,
|
||||
forNodeBody
|
||||
);
|
||||
}
|
||||
case "WhileStatement": {
|
||||
return builder.whileStatement(
|
||||
convert(node.test),
|
||||
convert(node.body)
|
||||
);
|
||||
const whileNodeTest = convert(node.test);
|
||||
const whileNodeBody = convert(node.body);
|
||||
|
||||
if (!whileNodeTest || !whileNodeBody) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return builder.whileStatement(whileNodeTest, whileNodeBody);
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
|
||||
@ -66,6 +66,90 @@ function render(input, out, __component, component, state) {
|
||||
if (z) {
|
||||
marko_dynamicTag(renderD, {}, out, __component, "17");
|
||||
}
|
||||
|
||||
// if.test
|
||||
if (async () => {}) {
|
||||
renderBody(out);
|
||||
}
|
||||
|
||||
// if.consequent
|
||||
if (true) {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
// if.alternate
|
||||
if (false) {
|
||||
} else {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
// elseif.test
|
||||
if (false) {
|
||||
} else if (async () => {}) {
|
||||
renderBody(out);
|
||||
}
|
||||
|
||||
// elseif.consequent
|
||||
if (false) {
|
||||
} else if (true) {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
// elseif.alternate
|
||||
if (false) {
|
||||
} else if (false) {
|
||||
} else {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
// for.init
|
||||
for (let x = (async () => {}); x < y; x++) {
|
||||
renderBody(out);
|
||||
}
|
||||
|
||||
// for.test
|
||||
for (let x = 1; (async () => {}); x++) {
|
||||
renderBody(out);
|
||||
}
|
||||
|
||||
// for.update
|
||||
for (let x = 1; x < y; (async () => {})) {
|
||||
renderBody(out);
|
||||
}
|
||||
|
||||
// for.body
|
||||
for (let x = 1; x < y; x++) {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
// while.test
|
||||
while ((async () => {})) {
|
||||
renderBody(out);
|
||||
}
|
||||
|
||||
// while.body
|
||||
while (true) {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
// dowhile.body
|
||||
do {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
marko_template._ = marko_renderer(render, {
|
||||
|
||||
@ -31,4 +31,115 @@ $ while (i--) {
|
||||
input.renderBody(out);
|
||||
}
|
||||
|
||||
$ if (z) renderD(out);
|
||||
$ if (z) renderD(out);
|
||||
|
||||
// The following usages cannot be migrated as the syntax causes them to bail out
|
||||
$ {
|
||||
// if.test
|
||||
if (async () => {}) {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// if.consequent
|
||||
if (true) {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// if.alternate
|
||||
if (false) {
|
||||
} else {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// elseif.test
|
||||
if (false) {
|
||||
} else if (async () => {}) {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// elseif.consequent
|
||||
if (false) {
|
||||
} else if (true) {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// elseif.alternate
|
||||
if (false) {
|
||||
} else if (false) {
|
||||
} else {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// for.init
|
||||
for (let x = (async () => {}); x < y; x++) {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// for.test
|
||||
for (let x = 1; (async () => {}); x++) {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// for.update
|
||||
for (let x = 1; x < y; (async () => {})) {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// for.body
|
||||
for (let x = 1; x < y; x++) {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// while.test
|
||||
while ((async () => {})) {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// while.body
|
||||
while (true) {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ {
|
||||
// dowhile.body
|
||||
do {
|
||||
async function x() {
|
||||
renderBody(out);
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
@ -2,18 +2,15 @@
|
||||
|
||||
var marko_template = module.exports = require("marko/src/html").t(__filename),
|
||||
marko_component = {
|
||||
onCreate: function() {
|
||||
this.state = {
|
||||
message: "didnt run it"
|
||||
};
|
||||
|
||||
if (true) {
|
||||
onCreate: function () {
|
||||
this.state = { message: 'didnt run it' };
|
||||
if (true) {
|
||||
runIt(() => {
|
||||
this.state.message = 'ran it';
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
marko_componentType = "/marko-test$1.0.0/components-compilation/fixtures-html/arrow-functions/index.marko",
|
||||
components_helpers = require("marko/src/components/helpers"),
|
||||
marko_renderer = components_helpers.r,
|
||||
|
||||
@ -1 +0,0 @@
|
||||
module.exports.fails = "issue #1181";
|
||||
Loading…
x
Reference in New Issue
Block a user