File tree Expand file tree Collapse file tree 3 files changed +23
-15
lines changed Expand file tree Collapse file tree 3 files changed +23
-15
lines changed Original file line number Diff line number Diff line change 1- import esprima from 'esprima ' ;
1+ import { parse } from '@babel/parser ' ;
22import { gulpPlugin } from 'gulp-plugin-extras' ;
33
44export default function gulpJsValidate ( { module : useModule = true } = { } ) {
5- const parse = useModule ? esprima . parseModule : esprima . parseScript ;
6-
75 return gulpPlugin ( 'gulp-jsvalidate' , file => {
8- const { errors} = parse ( file . contents . toString ( ) , { tolerant : true } ) ;
6+ try {
7+ parse ( file . contents . toString ( ) , {
8+ sourceType : useModule ? 'module' : 'script' ,
9+ sourceFilename : file . basename ,
10+ } ) ;
11+ } catch ( error ) {
12+ if ( error instanceof SyntaxError ) {
13+ const formattedError = new Error ( `\n${ error . message } ` ) ;
14+ formattedError . isPresentable = true ;
15+ throw formattedError ;
16+ }
917
10- if ( errors . length > 0 ) {
11- const error = new Error ( `\n${ errors . join ( '\n' ) } ` ) ;
12- error . isPresentable = true ;
1318 throw error ;
1419 }
1520
Original file line number Diff line number Diff line change 1212 },
1313 "type" : " module" ,
1414 "exports" : " ./index.js" ,
15+ "sideEffects" : false ,
1516 "engines" : {
1617 "node" : " >=18"
1718 },
3637 " code"
3738 ],
3839 "dependencies" : {
39- "esprima " : " ^4.0.1 " ,
40- "gulp-plugin-extras" : " ^0.2.2 "
40+ "@babel/parser " : " ^7.25.3 " ,
41+ "gulp-plugin-extras" : " ^1.0.0 "
4142 },
4243 "devDependencies" : {
43- "ava" : " ^5.3.1 " ,
44- "gulp" : " ^4 .0.2 " ,
45- "p-event" : " ^6.0.0 " ,
44+ "ava" : " ^6.1.3 " ,
45+ "gulp" : " ^5 .0.0 " ,
46+ "p-event" : " ^6.0.1 " ,
4647 "vinyl" : " ^3.0.0" ,
47- "xo" : " ^0.56.0 "
48+ "xo" : " ^0.59.3 "
4849 },
4950 "peerDependencies" : {
5051 "gulp" : " >=4"
Original file line number Diff line number Diff line change @@ -9,17 +9,19 @@ test('main', async t => {
99 const errorPromise = pEvent ( stream ) ;
1010
1111 stream . end ( new Vinyl ( {
12- contents : Buffer . from ( 'const foo = \'bar;' ) ,
12+ path : import . meta. url ,
13+ contents : Buffer . from ( 'const foo = \'bar;\nlet undefinedVariable;undefinedVariable ??= \'Hello\';' ) ,
1314 } ) ) ;
1415
15- await t . throwsAsync ( errorPromise , { message : / U n e x p e c t e d t o k e n / } ) ;
16+ await t . throwsAsync ( errorPromise , { message : / U n t e r m i n a t e d s t r i n g c o n s t a n t / } ) ;
1617} ) ;
1718
1819test ( 'supports `import`' , async t => {
1920 const stream = gulpJsvalidate ( ) ;
2021 const errorPromise = pEvent ( stream , 'data' ) ;
2122
2223 stream . end ( new Vinyl ( {
24+ path : import . meta. url ,
2325 contents : Buffer . from ( 'import foo from \'foo\';' ) ,
2426 } ) ) ;
2527
You can’t perform that action at this time.
0 commit comments