Skip to main content
Inspiring
October 16, 2023
Question

#include

  • October 16, 2023
  • 3 replies
  • 516 views

when jsx file is included in another script file, is it possible to find out by what file its included without passing parameters?

 

lets say I have 2 files:

 

lib.jsx

--

function libFunc(){

var main=???

$.writeln("I am oncluded in"+main);

};

libFunc();

 

~eof

 

main.jsx:

 

#include lib.jsx

 

~eof

 

 

 

This topic has been closed for replies.

3 replies

Legend
October 16, 2023

Re-reading the original question after the first answer (sorry), this appears to be more about the top level execution rather than variable redeclarations. The mentioned $.stack and $.fileName are as close as you can get.

dolce5EC2Author
Inspiring
October 17, 2023

really creative ideas about const and watch, thank you! but file name in lib.jsx still point to lib.jsx location, not main.jsx 😞

Legend
October 16, 2023

While this is not possible after the fact, there are multiple close possibilities.

 

Note that some of the global variables are introduced by cross-suite startup scripts of Adobe themselves, you would not find those.

E.g. an illustrator startup introduces subMenuBrush and several others in code that should only target Bridge.

Same with photoshop which is responsible for that tempPSVersionInfo.

 

For your own scripts:

 

You can declare the global as const rather than variable.

The redeclaration within your nested code will then fail with an error.

You would use that e.g. to track down forgotten "var" that would place them in local scope.

 

You can also trap write access via Object.prototype.watch().

The global object is available via $.global.

In your watch callback, you can also look at the call stack via $.stack .

 

femkeblanco
Legend
October 16, 2023

The question is unclear to me.  Are you asking how to distinguish between variables from the included file and variables from the main file?  If so, the answer is: not possible.  Both sets of variables are added as properties to the same global object. 

dolce5EC2Author
Inspiring
October 17, 2023

$.fileName in lib.jsx points to ~/desktop/lib.jsx

..and I want to find out tests.jsx name somehow in lib..

 


create 2 files, lib.jsx and test.jsx and try runing test.jsx

lib.jx:

alert($.fileName)

~eof

test.jsx:

//@include lib.jsx

~eof