Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Error: Illegal #include (Preprocessor.js:225) #10

Open
markusha opened this issue Jun 8, 2014 · 5 comments
Open

Error: Illegal #include (Preprocessor.js:225) #10

markusha opened this issue Jun 8, 2014 · 5 comments

Comments

@markusha
Copy link

markusha commented Jun 8, 2014

  1. Create a file test.js with the following content:
// #ifndef TEST
// #define var TEST=true
console.log('test');
// #endif
  1. Create a file main.js with the following content:
// #include "test.js"
console.log('testing include');
// #include "test.js"
  1. Preprocess main.js.

Result:
The file test.js is included twice in the output file.
The following error is shown:

C:\programs\nodejs\node_modules\preprocessor\Preprocessor.js:225
                        throw(new Error("Illegal #"+match[2]+": "+this.source.
                              ^
Error: Illegal #include: // #include "test.js
...
    at Preprocessor.process (C:\programs\nodejs\node_modules\preprocessor\Preprocessor.js:225:31)
    at Object.<anonymous> (C:\programs\nodejs\node_modules\preprocessor\bin\preprocess:65:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

Expected result:
The file test.js is included only once in the output file.
No errors are shown.

P. S. I see that there's an undocumented directive #include_once for such cases. But still this is an error.

@markusha
Copy link
Author

markusha commented Jun 8, 2014

My bad. The error was shown due to my slow typing/quick reaction of a script that runs the preprocessor.
But still the file test.js was included twice in the output file.

@dcodeIO
Copy link
Owner

dcodeIO commented Jun 8, 2014

Maybe I miss something, but for a main.js with contents

// #include "test.js"
console.log('testing include');
// #include "test.js"

the file test.js is of course included twice, while for

// #include_once "test.js"
console.log('testing include');
// #include_once "test.js"

it's not.

@markusha
Copy link
Author

markusha commented Jun 9, 2014

Ah, again my bad for not specifically describing the problem.
The file test.js in this case must indeed be included in main.js twice. But the thing is that the contents of the file test.js, specifically console.log('test');, will be included twice too. Which is an error because #ifndef from the second inclusion must prevent this.

@dcodeIO
Copy link
Owner

dcodeIO commented Jun 9, 2014

I see. Well, the issue here is that #define is quite a hack currently and does not play well with #ifdef, which is of course bad and I'd need to invest some time to rethink both.

Personally, I am migrating all my projects to MetaScript currently (e.g. https://github.com/dcodeIO/ByteBuffer.js/tree/master/src), which is a more javascripty way of preprocessing, and I'd recommend that you'd do the same.

test.js

//? if (typeof TEST === 'undefined') { TEST = true;
console.log("test");
//? }

main.js

//? include("test.js");
console.log('testing include');
//? include("test.js");

which does exactly what you need.

@markusha
Copy link
Author

Personally, I am migrating all my projects to MetaScript

Thanks for the tip.

STAH added a commit to nashdot/Preprocessor.js that referenced this issue Feb 3, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants