Unintuitive here document behavior: bug or feature?
Anthony Vanelverdinghe
anthony.vanelverdinghe at gmail.com
Mon Feb 23 18:50:46 UTC 2015
Hi
I see the bug has been resolved as not an issue. However, in my opinion
this behavior is sufficiently unintuitive that it should at least be
documented:
- as far as I know, appending commands after the starting "<<EOD" is not
possible in a bash script (already the fact that in Nashorn the "<<EOD"
is actually embedded in the statement, as in "print(<<EOD);", is pretty
unique, I believe)
- moreover, users that are unaware of this behavior, may start writing
text on the same line & will get errors at runtime. For example:
print(<<EOD); This is line 1.
And this is line 2.
EOD
results in:
test.js:3:-33 Expected ; but found is
print(<<EOD); This is line 1.
^
and:
print(<<EOD); This
And this is line 2.
EOD
results in:
And this is line 2.
test.js:3 ReferenceError: "This" is not defined
(also note that the error refers to line 3 in both cases, even though
line 3 just contains the closing delimiter)
So in conclusion, I would like to ask for this bug to be reopened, with
the goal to specify this behavior in the appropriate section of the
Nashorn user guide [1]. Thanks in advance for your consideration.
Kind regards, Anthony
[1]
http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/shell.html#sthref26
On 23/02/2015 4:46, A. Sundararajan wrote:
> Hi,
>
> It appears to be a bug to me. Thanks for reporting. I filed
> https://bugs.openjdk.java.net/browse/JDK-8073612
>
> Thanks,
> -Sundar
>
> On Sunday 22 February 2015 04:42 PM, Anthony Vanelverdinghe wrote:
>> Hi
>>
>> When using a here document, statements that are on the same line as
>> the initial <<EOD are interpreted as JavaScript & executed after the
>> "heredoc statement". Is this a bug or a feature?
>>
>> For example:
>>
>> var a = 2;
>> print(<<EOD); a = 3; print("here")
>> a++;
>> ${a}
>> EOD
>> print(a);
>>
>> prints
>>
>> a++;
>> 2
>> here
>> 3
>>
>> Kind regards, Anthony
>
>
More information about the nashorn-dev
mailing list