1- import { acornParse } from "../../analysis/FileAnalysis" ;
2- import { PackageAbstraction } from "./PackageAbstraction" ;
3- import { ASTTraverse } from "../../ASTTraverse" ;
4- import { RequireStatement } from "./nodes/RequireStatement" ;
51import * as escodegen from "escodegen" ;
62import * as path from "path" ;
3+ import { acornParse } from "../../analysis/FileAnalysis" ;
4+ import { ASTTraverse } from "../../ASTTraverse" ;
75import { ensureFuseBoxPath , transpileToEs5 } from "../../Utils" ;
8-
6+ import { QuantumBit } from "../plugin/QuantumBit" ;
7+ import { QuantumCore } from "../plugin/QuantumCore" ;
98import {
9+ compareStatement ,
10+ isExportComputed ,
11+ isExportMisused ,
12+ isTrueRequireFunction ,
13+ matcheObjectDefineProperty ,
1014 matchesAssignmentExpression ,
11- matchesLiteralStringExpression ,
12- matchesSingleFunction ,
15+ matchesDefinedExpression ,
1316 matchesDoubleMemberExpression ,
14- matcheObjectDefineProperty ,
1517 matchesEcmaScript6 ,
18+ matchesExportReference ,
19+ matchesGlobalVariable ,
20+ matchesIfStatementFuseBoxIsEnvironment ,
21+ matchesIfStatementProcessEnv ,
22+ matchesLiteralStringExpression ,
23+ matchesNodeEnv ,
24+ matchesSingleFunction ,
1625 matchesTypeOf ,
26+ matchNamedExport ,
1727 matchRequireIdentifier ,
1828 trackRequireMember ,
19- matchNamedExport ,
20- isExportMisused ,
21- matchesNodeEnv ,
22- matchesExportReference ,
23- matchesIfStatementProcessEnv ,
24- compareStatement ,
25- matchesIfStatementFuseBoxIsEnvironment ,
26- isExportComputed ,
27- isTrueRequireFunction ,
28- matchesDefinedExpression ,
29+ matchesVariableDeclarator ,
30+ matchesGlobalVariableReference ,
2931} from "./AstUtils" ;
3032import { ExportsInterop } from "./nodes/ExportsInterop" ;
31- import { UseStrict } from "./nodes/UseStrict" ;
33+ import { GenericAst } from "./nodes/GenericAst" ;
34+ import { NamedExport } from "./nodes/NamedExport" ;
35+ import { ReplaceableBlock } from "./nodes/ReplaceableBlock" ;
36+ import { RequireStatement } from "./nodes/RequireStatement" ;
3237import { TypeOfExportsKeyword } from "./nodes/TypeOfExportsKeyword" ;
3338import { TypeOfModuleKeyword } from "./nodes/TypeOfModuleKeyword" ;
3439import { TypeOfWindowKeyword } from "./nodes/TypeOfWindowKeyword" ;
35- import { NamedExport } from "./nodes/NamedExport" ;
36- import { GenericAst } from "./nodes/GenericAst" ;
37- import { QuantumCore } from "../plugin/QuantumCore" ;
38- import { ReplaceableBlock } from "./nodes/ReplaceableBlock" ;
39- import { QuantumBit } from "../plugin/QuantumBit" ;
40+ import { UseStrict } from "./nodes/UseStrict" ;
41+ import { PackageAbstraction } from "./PackageAbstraction" ;
4042
4143const globalNames = new Set < string > ( [ "__filename" , "__dirname" , "exports" , "module" ] ) ;
4244
@@ -75,6 +77,9 @@ export class FileAbstraction {
7577 public typeofGlobalKeywords = new Set < GenericAst > ( ) ;
7678 public typeofDefineKeywords = new Set < GenericAst > ( ) ;
7779 public typeofRequireKeywords = new Set < GenericAst > ( ) ;
80+ public globalProcess : Set < GenericAst > ;
81+ public globalProcessVersion : Set < GenericAst > ;
82+ public processVariableDefined : boolean ;
7883
7984 public namedExports = new Map < string , NamedExport > ( ) ;
8085 public processNodeEnv = new Set < ReplaceableBlock > ( ) ;
@@ -90,9 +95,15 @@ export class FileAbstraction {
9095 private removalRestricted = false ;
9196 private dependencies = new Map < FileAbstraction , Set < RequireStatement > > ( ) ;
9297
98+ public renderedHeaders : string [ ] ;
99+
93100 constructor ( public fuseBoxPath : string , public packageAbstraction : PackageAbstraction ) {
94101 this . fuseBoxDir = ensureFuseBoxPath ( path . dirname ( fuseBoxPath ) ) ;
95102 this . setID ( fuseBoxPath ) ;
103+ this . globalProcess = new Set ( ) ;
104+ this . renderedHeaders = [ ] ;
105+ this . globalProcessVersion = new Set ( ) ;
106+ this . processVariableDefined = false ;
96107 packageAbstraction . registerFileAbstraction ( this ) ;
97108 this . core = this . packageAbstraction . bundleAbstraction . producerAbstraction . quantumCore ;
98109
@@ -269,6 +280,9 @@ export class FileAbstraction {
269280 if ( this . isDirnameUsed ( ) ) {
270281 fn . push ( `var __dirname = ${ JSON . stringify ( this . fuseBoxDir ) } ;` + "\n" ) ;
271282 }
283+ if ( this . renderedHeaders . length ) {
284+ fn . push ( this . renderedHeaders . join ( "\n" ) + "\n" ) ;
285+ }
272286 if ( this . isFilenameUsed ( ) ) {
273287 fn . push ( `var __filename = ${ JSON . stringify ( this . fuseBoxPath ) } ;` + "\n" ) ;
274288 }
@@ -286,6 +300,7 @@ export class FileAbstraction {
286300 */
287301 private onNode ( node , parent , prop , idx ) {
288302 // process.env
303+
289304 if ( this . core ) {
290305 if ( this . core . opts . definedExpressions ) {
291306 const matchedExpression = matchesDefinedExpression ( node , this . core . opts . definedExpressions ) ;
@@ -364,6 +379,15 @@ export class FileAbstraction {
364379 }
365380 }
366381
382+ if ( matchesGlobalVariable ( node , "process" ) ) {
383+ this . globalProcess . add ( new GenericAst ( parent , prop , node ) ) ;
384+ }
385+ if ( matchesGlobalVariableReference ( node , "process.version" ) ) {
386+ this . globalProcessVersion . add ( new GenericAst ( parent , prop , node ) ) ;
387+ }
388+ if ( matchesVariableDeclarator ( node , "process" ) ) {
389+ this . processVariableDefined = true ;
390+ }
367391 // detecting es6
368392 if ( matchesEcmaScript6 ( node ) ) {
369393 this . isEcmaScript6 = true ;
0 commit comments