@@ -38,12 +38,12 @@ describe('JavaScriptTransformer sourcemaps', () => {
3838 const inputMap = {
3939 version : 3 ,
4040 sources : [ 'src/app.ts' ] ,
41- sourcesContent : [ 'const x = new SomeClass(); ' ] ,
41+ sourcesContent : [ 'export class MyClass { static ɵprov = 42; } ' ] ,
4242 mappings : 'AAAA' ,
4343 names : [ ] ,
4444 } ;
4545 const base64Map = Buffer . from ( JSON . stringify ( inputMap ) ) . toString ( 'base64' ) ;
46- const input = `var x = new SomeClass(); \n//# sourceMappingURL=data:application/json;base64,${ base64Map } ` ;
46+ const input = `export class MyClass { static ɵprov = 42; } \n//# sourceMappingURL=data:application/json;base64,${ base64Map } ` ;
4747
4848 const result = await transformer . transformData ( 'src/app.js' , input , true ) ;
4949 const text = Buffer . from ( result ) . toString ( 'utf-8' ) ;
@@ -157,7 +157,7 @@ describe('JavaScriptTransformer sourcemaps', () => {
157157 1 ,
158158 ) ;
159159
160- const input = 'var x = new SomeClass(); ' ;
160+ const input = 'export class MyClass { static ɵprov = 42; } ' ;
161161 const result = await transformer . transformData ( 'src/app.js' , input , true ) ;
162162 const text = Buffer . from ( result ) . toString ( 'utf-8' ) ;
163163 const map = extractSourcemap ( text ) ;
@@ -249,7 +249,7 @@ describe('JavaScriptTransformer sourcemaps', () => {
249249 1 ,
250250 ) ;
251251
252- const inputBuffer = Buffer . from ( 'var x = new SomeClass(); ' , 'utf-8' ) ;
252+ const inputBuffer = Buffer . from ( 'export class MyClass { static ɵprov = 42; } ' , 'utf-8' ) ;
253253 const result = await transformer . transformData ( 'src/app.js' , inputBuffer , true ) ;
254254 const text = Buffer . from ( result ) . toString ( 'utf-8' ) ;
255255 const map = extractSourcemap ( text ) ;
@@ -374,4 +374,143 @@ describe('JavaScriptTransformer sourcemaps', () => {
374374
375375 expect ( text ) . not . toContain ( 'i0.ɵɵngDeclareDirective' ) ;
376376 } ) ;
377+
378+ describe ( 'advanced optimizations fast-path pre-filter' , ( ) => {
379+ it ( 'should bypass worker and return input buffer directly when no candidate tokens are present' , async ( ) => {
380+ transformer = new JavaScriptTransformer (
381+ {
382+ sourcemap : false ,
383+ advancedOptimizations : true ,
384+ } ,
385+ 1 ,
386+ ) ;
387+
388+ const inputBuffer = Buffer . from (
389+ 'function add(a, b) { return a + b; }\nconst result = add(1, 2);' ,
390+ 'utf-8' ,
391+ ) ;
392+ const result = await transformer . transformData ( 'src/math.js' , inputBuffer , true ) ;
393+
394+ expect ( result ) . toBe ( inputBuffer ) ;
395+ } ) ;
396+
397+ it ( 'should bypass worker for standard classes without static properties' , async ( ) => {
398+ transformer = new JavaScriptTransformer (
399+ {
400+ sourcemap : false ,
401+ advancedOptimizations : true ,
402+ } ,
403+ 1 ,
404+ ) ;
405+
406+ const inputBuffer = Buffer . from (
407+ `export class UserService {
408+ constructor(http) { this.http = http; }
409+ getUser(id) { return this.http.get('/users/' + id); }
410+ }` ,
411+ 'utf-8' ,
412+ ) ;
413+ const result = await transformer . transformData ( 'src/user.service.js' , inputBuffer , true ) ;
414+
415+ expect ( result ) . toBe ( inputBuffer ) ;
416+ } ) ;
417+
418+ it ( 'should bypass worker for default exports without static properties or Angular metadata' , async ( ) => {
419+ transformer = new JavaScriptTransformer (
420+ {
421+ sourcemap : false ,
422+ advancedOptimizations : true ,
423+ } ,
424+ 1 ,
425+ ) ;
426+
427+ const inputBuffer = Buffer . from (
428+ `export default class UserService {
429+ constructor(http) { this.http = http; }
430+ getUser(id) { return this.http.get('/users/' + id); }
431+ }` ,
432+ 'utf-8' ,
433+ ) ;
434+ const result = await transformer . transformData ( 'src/user.service.js' , inputBuffer , true ) ;
435+
436+ expect ( result ) . toBe ( inputBuffer ) ;
437+ } ) ;
438+
439+ it ( 'should bypass worker for classes with static members when no Angular metadata is present' , async ( ) => {
440+ transformer = new JavaScriptTransformer (
441+ {
442+ sourcemap : false ,
443+ advancedOptimizations : true ,
444+ } ,
445+ 1 ,
446+ ) ;
447+
448+ const inputBuffer = Buffer . from ( 'export class MyComponent { static prop = 42; }' , 'utf-8' ) ;
449+ const result = await transformer . transformData ( 'src/component.js' , inputBuffer , true ) ;
450+
451+ expect ( result ) . toBe ( inputBuffer ) ;
452+ } ) ;
453+
454+ it ( 'should dispatch to worker when Angular tokens are present' , async ( ) => {
455+ transformer = new JavaScriptTransformer (
456+ {
457+ sourcemap : false ,
458+ advancedOptimizations : true ,
459+ } ,
460+ 1 ,
461+ ) ;
462+
463+ const input = 'export class MyService { static ɵprov = true; }' ;
464+ const result = await transformer . transformData ( 'src/service.js' , input , true ) ;
465+ const text = Buffer . from ( result ) . toString ( 'utf-8' ) ;
466+
467+ expect ( text ) . toContain ( 'let MyService = /*#__PURE__*/ (() => {' ) ;
468+ } ) ;
469+
470+ it ( 'should dispatch to worker when decorator tokens are present and sideEffects is false' , async ( ) => {
471+ transformer = new JavaScriptTransformer (
472+ {
473+ sourcemap : false ,
474+ advancedOptimizations : true ,
475+ } ,
476+ 1 ,
477+ ) ;
478+
479+ const inputBuffer = Buffer . from ( 'const MyClass = __decorate([], class {});' , 'utf-8' ) ;
480+ const result = await transformer . transformData ( 'src/class.js' , inputBuffer , true , false ) ;
481+
482+ expect ( result ) . not . toBe ( inputBuffer ) ;
483+ } ) ;
484+
485+ it ( 'should bypass worker and return converted buffer when no candidate tokens are present in string input' , async ( ) => {
486+ transformer = new JavaScriptTransformer (
487+ {
488+ sourcemap : false ,
489+ advancedOptimizations : true ,
490+ } ,
491+ 1 ,
492+ ) ;
493+
494+ const inputString = 'function multiply(a, b) { return a * b; }' ;
495+ const result = await transformer . transformData ( 'src/math.js' , inputString , true ) ;
496+
497+ expect ( Buffer . from ( result ) . toString ( 'utf-8' ) ) . toBe ( inputString ) ;
498+ } ) ;
499+
500+ it ( 'should dispatch to worker when candidate tokens are present in string input' , async ( ) => {
501+ transformer = new JavaScriptTransformer (
502+ {
503+ sourcemap : false ,
504+ advancedOptimizations : true ,
505+ } ,
506+ 1 ,
507+ ) ;
508+
509+ const inputString = 'export class MyService { static ɵprov = true; }' ;
510+ const result = await transformer . transformData ( 'src/service.js' , inputString , true ) ;
511+ const text = Buffer . from ( result ) . toString ( 'utf-8' ) ;
512+
513+ expect ( text ) . toContain ( 'let MyService = /*#__PURE__*/ (() => {' ) ;
514+ } ) ;
515+ } ) ;
377516} ) ;
0 commit comments