Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f5b4cf

Browse files
committed
1 parent98414f9 commit9f5b4cf

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

‎lib/parse.js‎

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -304,30 +304,42 @@ const parse = (input, options = {}) => {
304304
push({type:'text', value});
305305
}
306306

307+
flattenBlocks(stack)
308+
markImbalancedBraces(ast);
309+
push({type:'eos'});
310+
311+
returnast;
312+
};
313+
314+
module.exports=parse;
315+
316+
functionmarkImbalancedBraces({nodes}){
307317
// Mark imbalanced braces and brackets as invalid
318+
for(constnodeofnodes){
319+
if(node.nodes||node.invalid)
320+
continue;
321+
322+
if(node.type==='open')node.isOpen=true;
323+
if(node.type==='close')node.isClose=true;
324+
if(!node.nodes)node.type='text';
325+
326+
node.invalid=true;
327+
deletenode.parent;
328+
}
329+
}
330+
331+
functionflattenBlocks(stack){
332+
letblock;
308333
do{
309334
block=stack.pop();
310335

311-
if(block.type!=='root'){
312-
block.nodes.forEach(node=>{
313-
if(!node.nodes){
314-
if(node.type==='open')node.isOpen=true;
315-
if(node.type==='close')node.isClose=true;
316-
if(!node.nodes)node.type='text';
317-
node.invalid=true;
318-
}
319-
});
336+
if(block.type==='root')
337+
continue;
320338

321-
// get the location of the block on parent.nodes (block's siblings)
322-
letparent=stack[stack.length-1];
323-
letindex=parent.nodes.indexOf(block);
324-
// replace the (invalid) block with it's nodes
325-
parent.nodes.splice(index,1, ...block.nodes);
326-
}
339+
// get the location of the block on parent.nodes (block's siblings)
340+
letparent=stack.at(-1);
341+
letindex=parent.nodes.indexOf(block);
342+
// replace the (invalid) block with its nodes
343+
parent.nodes.splice(index,1, ...block.nodes);
327344
}while(stack.length>0);
328-
329-
push({type:'eos'});
330-
returnast;
331-
};
332-
333-
module.exports=parse;
345+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp