Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit b53644d

Browse files
darkwingjasonLaster
authored andcommitted
[PausePoints] lastStatement is undefined (#5828)
1 parent 47bf8a8 commit b53644d

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/workers/parser/pausePoints.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ function onEnter(node: BabelNode, ancestors: SimplePath[], state) {
135135

136136
if (t.isProgram(node)) {
137137
const lastStatement = node.body[node.body.length - 1];
138-
addPoint(state, lastStatement.loc.end);
138+
if (lastStatement) {
139+
addPoint(state, lastStatement.loc.end);
140+
}
139141
}
140142
}
141143

src/workers/parser/tests/__snapshots__/pausePoints.spec.js.snap

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,52 @@ const /*bs 25*/obj = {
9696
"
9797
`;
9898
99+
exports[`Parser.pausePoints html 1`] = `
100+
"<html>
101+
<head>
102+
<script type=\\"text/javascript\\">
103+
var /*bs 1*/globalObject = {
104+
first: \\"name\\",
105+
last: \\"words\\"
106+
};
107+
/*b 2*/function sayHello (name) {
108+
/*bs 3*/return \`Hello, \${name}!\`;
109+
/*bs 4*/}
110+
</script>
111+
<style>
112+
BODY {
113+
font-size: 48px;
114+
color: rebeccapurple;
115+
}
116+
</style>
117+
</head>
118+
<body>
119+
<h1>Testing Script Tags in HTML</h1>
120+
<script>
121+
const /*bs 5*/capitalize = /*b 6*/name => {
122+
/*bs 7*/return /*bs 8*/name[0]./*bs 9*/toUpperCase() + /*bs 10*/name./*bs 11*/substring(1)
123+
/*bs 12*/};
124+
const greetAll = /*bs 13*/[\\"my friend\\", \\"buddy\\", \\"world\\"]
125+
./*bs 14*/map(capitalize)
126+
./*bs 15*/map(sayHello)
127+
./*bs 16*/join(\\"\\\\n\\");
128+
129+
/*bs 17*/globalObject.greetings = greetAll;
130+
</script>
131+
<p>
132+
Some arbitrary intermediate content to affect the offsets of the scripts
133+
</p>
134+
<script>
135+
/*bs 18*/(/*b 19*/function iife() {
136+
const greeting = /*bs 20*/sayHello(\\"Ryan\\");
137+
/*bs 21*/console./*bs 22*/log(greeting);
138+
/*bs 23*/})();/*bs 24*/
139+
</script>
140+
</body>
141+
</html>
142+
"
143+
`;
144+
99145
exports[`Parser.pausePoints jsx 1`] = `
100146
"const jsxElement = /*bs 1*/<h1> Hi ! I'm here ! </h1>;
101147

src/workers/parser/tests/pausePoints.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ cases(
2525
{ name: "modules", file: "modules", original: true },
2626
{ name: "jsx", file: "jsx", original: true },
2727
{ name: "func", file: "func", original: true },
28-
{ name: "decorators", file: "decorators", original: true }
28+
{ name: "decorators", file: "decorators", original: true },
29+
{ name: "html", file: "parseScriptTags", type: "html" }
2930
]
3031
);

0 commit comments

Comments
 (0)