11'use strict' ;
22
33var fs = require ( 'fs' ) ,
4- path = require ( 'path' ) ,
5- through = require ( 'through2' ) ,
4+ path = require ( 'path' ) ;
5+
6+ var through = require ( 'through2' ) ,
67 merge = require ( 'lodash.merge' ) ,
78 trackFilenames = require ( 'gulp-track-filenames' ) ,
89 transformTools = require ( 'browserify-transform-tools' ) ,
@@ -49,7 +50,7 @@ function isMethodAST(node) {
4950 * @return A jasmine transform
5051 */
5152function jasmineTransform ( symbol ) {
52- return transformTools . makeFalafelTransform ( 'jasmineTransform' , null , function ( node , options , done ) {
53+ return transformTools . makeFalafelTransform ( 'jasmineTransform' , null , function jasmineASTWalker ( node , options , done ) {
5354 var isValid = isLiteralAST ( node , symbol ) && isMethodAST ( node . parent , 'describe' , 'module' ) ;
5455 if ( isValid ) {
5556 node . update ( '\'' + options . file . replace ( / \\ / g, '\\\\' ) + ':0:0\'' ) ;
@@ -178,26 +179,33 @@ function compile(bannerWidth, transforms) {
178179 // error handler
179180 var timeout ;
180181 function errorHandler ( error ) {
181- var text = error . toString ( ) ;
182- [
182+
183+ // run a bunch of tests against the error in order to determine the appropriate error message
184+ // there will be at least one truthy value, even if that is the final placeholder
185+ var text = error . toString ( ) ;
186+ var message = [
187+
183188 // SyntaxError: <file>:<reason>:<line>:<column>
184- function ( ) {
189+ function testSyntaxError ( ) {
185190 var analysis = / ^ \s * S y n t a x E r r o r \: \s * ( [ ^ : ] * ) \s * \: \s * ( [ ^ ( ] * ) \s * \( ( \d + : \d + ) \) \s * \n / . exec ( text ) ;
186191 return analysis && ( [ analysis [ 1 ] , analysis [ 3 ] , analysis [ 2 ] ] . join ( ':' ) + '\n' ) ;
187192 } ,
193+
188194 // Error: SyntaxError: <reason> while parsing json file <file>
189- function ( ) {
195+ function testSyntaxErrorJSON ( ) {
190196 var analysis = / ^ \s * E r r o r : S y n t a x E r r o r \: \s * ( .* ) \s * w h i l e p a r s i n g j s o n f i l e \s * ( [ ^ ] * ) / . exec ( text ) ;
191197 return analysis && ( [ analysis [ 2 ] , '0' , '0' , ' ' + analysis [ 1 ] ] . join ( ':' ) + '\n' ) ;
192198 } ,
199+
193200 // Line <line>: <reason>: <file>
194- function ( ) {
201+ function testGeneric ( ) {
195202 var analysis = / L i n e \s * ( \d + ) \s * \: \s * ( [ ^ : ] * ) \s * : \s * ( .* ) \s * / . exec ( text ) ;
196203 return analysis && ( [ analysis [ 3 ] , analysis [ 1 ] , 0 , ' ' + analysis [ 2 ] ] . join ( ':' ) + '\n' ) ;
197204 } ,
205+
198206 // Error: Cannot find module '<reason>' from '<directory>'
199207 // find the first text match for any text quoted in <reason>
200- function ( ) {
208+ function testBadImport ( ) {
201209 var analysis = / ^ \s * E r r o r \: C a n n o t f i n d m o d u l e ' ( .* ) \' \s * f r o m \s * \' ( .* ) \' \s * $ / . exec ( text ) ;
202210 if ( analysis ) {
203211 var filename = fs . readdirSync ( analysis [ 2 ] )
@@ -211,20 +219,22 @@ function compile(bannerWidth, transforms) {
211219 return path . join ( analysis [ 2 ] , filename ) + ':0:0: Cannot find import ' + analysis [ 1 ] + '\n' ;
212220 }
213221 } ,
222+
214223 // Unknown
215- function ( ) {
224+ function otherwise ( ) {
216225 return 'TODO parse this error\n' + text + '\n' ;
217226 }
218227 ]
219- . map ( function ( method ) {
220- return method ( ) ;
228+ . map ( function invokeTestMethod ( testMethod ) {
229+ return testMethod ( ) ;
221230 } )
222231 . filter ( Boolean )
223- . forEach ( function addUnique ( message ) {
224- if ( output . indexOf ( message ) < 0 ) {
225- output . push ( message ) ;
226- }
227- } ) ;
232+ . shift ( ) ;
233+
234+ // add unique
235+ if ( output . indexOf ( message ) < 0 ) {
236+ output . push ( message ) ;
237+ }
228238
229239 // complete overall only once there are no further errors
230240 clearTimeout ( timeout ) ;
@@ -247,7 +257,7 @@ function compile(bannerWidth, transforms) {
247257 // transforms
248258 transforms
249259 . concat ( requireTransform ( false ) )
250- . forEach ( function ( item , i , list ) {
260+ . forEach ( function eachItem ( item , i , list ) {
251261 if ( typeof item === 'function' ) {
252262 var opts = ( typeof list [ i + 1 ] === 'object' ) ? merge ( { global : true } , list [ i + 1 ] ) : { global : true } ;
253263 bundler . transform ( item , opts ) ;
@@ -256,7 +266,7 @@ function compile(bannerWidth, transforms) {
256266
257267 // require statements
258268 [ ] . concat ( files )
259- . forEach ( function ( item ) {
269+ . forEach ( function eachItem ( item ) {
260270 bundler . require ( item , { entry : true } ) ;
261271 } ) ;
262272
@@ -278,7 +288,7 @@ function compile(bannerWidth, transforms) {
278288
279289 // when we use minification we will get: error, code, source-map
280290 // when we don't we will get: error, buffer(with embedded source map)
281- bundler . bundle ( function ( error , codeOrBuffer , map ) {
291+ bundler . bundle ( function onComplete ( error , codeOrBuffer , map ) {
282292 if ( ! error ) {
283293 var code = codeOrBuffer . toString ( ) ;
284294 var sourceMap = map ? JSON . parse ( map ) : convert . fromComment ( code ) . toObject ( ) ;
@@ -305,10 +315,10 @@ function compile(bannerWidth, transforms) {
305315 * @param {string } [sourceMapBase] Base path for source map file
306316 * @returns {stream.Through }
307317 */
308- each : function ( isMinify , sourceMapBase ) {
309- return through . obj ( function ( file , encoding , done ) {
318+ each : function gulpBundleEach ( isMinify , sourceMapBase ) {
319+ return through . obj ( function transformFn ( file , encoding , done ) {
310320 bundle ( this , [ file . path ] , file . relative , isMinify , sourceMapBase , done ) ;
311- } , function ( done ) {
321+ } , function flushFn ( done ) {
312322 flushErrors ( ) ;
313323 done ( ) ;
314324 } ) ;
@@ -321,12 +331,12 @@ function compile(bannerWidth, transforms) {
321331 * @param {string } [sourceMapBase] Base path for source map file
322332 * @returns {stream.Through }
323333 */
324- all : function ( outPath , isMinify , sourceMapBase ) {
334+ all : function gulpBundleAll ( outPath , isMinify , sourceMapBase ) {
325335 var pending = [ ] ;
326- return through . obj ( function ( file , encoding , done ) {
336+ return through . obj ( function transformFn ( file , encoding , done ) {
327337 pending . push ( file . path ) ;
328338 done ( ) ;
329- } , function ( done ) {
339+ } , function flushFn ( done ) {
330340 if ( pending . length ) {
331341 bundle ( this , pending , outPath , isMinify , sourceMapBase , function ( ) {
332342 flushErrors ( ) ;
0 commit comments