(Body Snatcher) Pass 3
This commit is contained in:
1 parent
d819146009
commit
832f3a3345
36 files changed
+6416
No files matched your search
@@ -0,0 +1,18 @@
|
||||
const fs=require('fs');
|
||||
let acorn;
|
||||
try{ acorn=require('acorn'); }catch(e){ try{ acorn=require('/opt/homebrew/lib/node_modules/eslint/node_modules/espree/node_modules/acorn'); }catch(e2){ try{acorn=require('/opt/homebrew/lib/node_modules/acorn')}catch(e3){ console.log('no acorn:',e3.message); process.exit(1);} } }
|
||||
const src=fs.readFileSync('index.html','utf8');
|
||||
const m=src.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);
|
||||
const code=m[1];
|
||||
const fileLineBase=src.slice(0,src.indexOf('<script')).split('\n').length;
|
||||
try{
|
||||
acorn.parse(code,{ecmaVersion:2022,sourceType:'script',allowReturnOutsideFunction:true});
|
||||
console.log('PARSE OK');
|
||||
}catch(e){
|
||||
const fl=(e.loc? (e.loc.line+fileLineBase-1):'?');
|
||||
console.log('ERROR: '+e.message+' at script-line '+(e.loc?e.loc.line:'?')+' col '+(e.loc?e.loc.column:'?')+' => FILE line '+fl);
|
||||
// print context
|
||||
const cl=code.split('\n');
|
||||
const sl=e.loc?e.loc.line:null;
|
||||
if(sl){ for(let k=Math.max(0,sl-4);k<=Math.min(cl.length-1,sl+1);k++) console.log((k+1===sl?'>>':' ')+(k+1)+'| '+cl[k]); }
|
||||
}
|
||||
Reference in new issue
Block a user