Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXEC command examples do not work. Should use var instead of const #41

Closed
koresar opened this issue Nov 1, 2018 · 5 comments
Closed

Comments

@koresar
Copy link

koresar commented Nov 1, 2018

I have just found out that if I use +++! const a=1;+++ command does not work. Throws Unknown symbol 'a'.

But as soon as I changed it to +++! var a=1;+++ the further usage of the a variable works.

Is it a known thing?

@guigrpa
Copy link
Owner

guigrpa commented Nov 4, 2018

+++! const a=1;+++ works on my machine, at least within the installed docx-templates repo and from the example-node directory. What Node version are you using? I've tried with v8.11.4, v9.11.2, v10.12.0 and v11.1.0 and it consistently works.

@vdechef
Copy link
Contributor

vdechef commented Nov 21, 2018

Same for me : I cannot reproduce it on my side.
@koresar could you give a full example to reproduce your problem ?

@razyon
Copy link

razyon commented Nov 27, 2018

@guigrpa Koresar is right, if you declare your variables as const in +++EXEC +++ you will be able to use them only in the exec script. If you want to access these variables in other +++EXEC +++ scripts or +++INS +++ you have to declare them more globally with var.

+++! const a=1;+++ is working but useless as you will never be able to access a in any other snippet.

To resume:

+++! const a='1';+++
+++= a+++

does not work

+++! var a='1';+++
+++= a+++

works

@guigrpa
Copy link
Owner

guigrpa commented Nov 30, 2018

@razyon I see! Thanks for the clarification. I guess the original post was missing the key part: "from another EXEC block".

#48 has just been merged explaining this in the docs. It's normal that variables declared with const are not visible, since they are local to the block in which they're defined. Use var instead, or just nothing at all: +++! a = '1'.

@guigrpa guigrpa closed this as completed Nov 30, 2018
@koresar
Copy link
Author

koresar commented Dec 1, 2018

Apologies for the misleading issue description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants