Officially support a shebang line

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Officially support a shebang line

Jan Krems
Tried to search past proposals for this but couldn't find one The short version: Most editors / syntax highlighting engines, non-engine parsers, node.js - they all support a leading shebang line in .js files. With the advent of ES6 modules it's the final holdout where node has to patch the script source to make V8 parse the code (and thus producing a mismatch between what's on disk and what the engine sees).

Is there a downside to allow any script or module to begin with the magical #! bytes? It should not break existing scripts because it's invalid syntax today & the parse overhead should be fairly limited.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Officially support a shebang line

Alexander Jones
It doesn't make any sense. The shebang is a UNIX way of declaring the interpreter for an executable script, not for hinting your syntax highlighter. If your file is not executable (as in, it can't be run with `./filename`, it shouldn't have a shebang).

On 19 May 2017 at 02:44, Jan Krems <[hidden email]> wrote:
Tried to search past proposals for this but couldn't find one The short version: Most editors / syntax highlighting engines, non-engine parsers, node.js - they all support a leading shebang line in .js files. With the advent of ES6 modules it's the final holdout where node has to patch the script source to make V8 parse the code (and thus producing a mismatch between what's on disk and what the engine sees).

Is there a downside to allow any script or module to begin with the magical #! bytes? It should not break existing scripts because it's invalid syntax today & the parse overhead should be fairly limited.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Officially support a shebang line

Jan Krems
Sorry, mentioning support in syntax highlighters might have been misleading. I am talking specifically about executable JavaScript scripts and modules. It's a common pattern in node to have programs written in JavaScript, with a shebang and the x flag set.

I just mentioned editor / syntax highlighter support to say "this is already de-facto part of real life JavaScript as it's understood by tools, it's just missing from the spec".

On Fri, May 19, 2017 at 1:44 AM Alexander Jones <[hidden email]> wrote:
It doesn't make any sense. The shebang is a UNIX way of declaring the interpreter for an executable script, not for hinting your syntax highlighter. If your file is not executable (as in, it can't be run with `./filename`, it shouldn't have a shebang).

On 19 May 2017 at 02:44, Jan Krems <[hidden email]> wrote:
Tried to search past proposals for this but couldn't find one The short version: Most editors / syntax highlighting engines, non-engine parsers, node.js - they all support a leading shebang line in .js files. With the advent of ES6 modules it's the final holdout where node has to patch the script source to make V8 parse the code (and thus producing a mismatch between what's on disk and what the engine sees).

Is there a downside to allow any script or module to begin with the magical #! bytes? It should not break existing scripts because it's invalid syntax today & the parse overhead should be fairly limited.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Officially support a shebang line

Wes Garland
In gpsee (using spidermonkey), we allow executable programs exactly the same way as a shell script, and there is no real penalty from a JavaScript parsing POV.  I'm not sure why node+v8 would be any different.  We just hand over the script to the parser with the pointer pointing to the newline at the end of the shebang.  This skips the syntax error and keeps the line numbers as expected.  As Alexander Jones explains, this shebang support stuff is deep in unix, and arrives by virtue of the exec-and-friends system calls declared in unitstd.h.

I suppose the one 'gotcha' here is that you can't have a module which can both act as a program and library.  We have the similar limitations in C - we have a special object file which has a symbol named 'main' and usually load library code as DSOs - but I never really found that to be a significant limitation in real-world work.

What is an example use-case that would take advantage of this proposal?

Wes


On 19 May 2017 at 10:25, Jan Krems <[hidden email]> wrote:
Sorry, mentioning support in syntax highlighters might have been misleading. I am talking specifically about executable JavaScript scripts and modules. It's a common pattern in node to have programs written in JavaScript, with a shebang and the x flag set.

I just mentioned editor / syntax highlighter support to say "this is already de-facto part of real life JavaScript as it's understood by tools, it's just missing from the spec".

On Fri, May 19, 2017 at 1:44 AM Alexander Jones <[hidden email]> wrote:
It doesn't make any sense. The shebang is a UNIX way of declaring the interpreter for an executable script, not for hinting your syntax highlighter. If your file is not executable (as in, it can't be run with `./filename`, it shouldn't have a shebang).

On 19 May 2017 at 02:44, Jan Krems <[hidden email]> wrote:
Tried to search past proposals for this but couldn't find one The short version: Most editors / syntax highlighting engines, non-engine parsers, node.js - they all support a leading shebang line in .js files. With the advent of ES6 modules it's the final holdout where node has to patch the script source to make V8 parse the code (and thus producing a mismatch between what's on disk and what the engine sees).

Is there a downside to allow any script or module to begin with the magical #! bytes? It should not break existing scripts because it's invalid syntax today & the parse overhead should be fairly limited.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




--
Wesley W. Garland
Director, Product Development
PageMail, Inc.
+1 613 542 2787 x 102

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Officially support a shebang line

Jan Krems
What is an example use-case that would take advantage of this proposal?

There's quite a few scripts in "node land" that can be both entry point (executable) and library. The rough idea is:

```
#!/usr/bin/env node
function myLibraryFunction(filename) {}
module.exports = myLibraryFunction;
if (process.mainModule === module) {
  console.log(myLibraryFunction(process.argv[2]));
}
```

It's not that uncommon for languages with C-like comment syntax to have special support for shebang "comments" in the first line. Prior work includes:

* Groovy ("1.4. Shebang line"): http://groovy-lang.org/syntax.html#_shebang_line
* Lua (only mentions the entry point but it also works in required modules): https://www.lua.org/manual/5.3/manual.html#7

For many other languages that can be used as executable scripts (*sh, Perl, PHP, Ruby, Python), the problem doesn't exist because they already allow # as line comments everywhere. Adding official support to JS would close a gap to most other scripting languages.

On Fri, May 19, 2017 at 8:15 AM Wes Garland <[hidden email]> wrote:
In gpsee (using spidermonkey), we allow executable programs exactly the same way as a shell script, and there is no real penalty from a JavaScript parsing POV.  I'm not sure why node+v8 would be any different.  We just hand over the script to the parser with the pointer pointing to the newline at the end of the shebang.  This skips the syntax error and keeps the line numbers as expected.  As Alexander Jones explains, this shebang support stuff is deep in unix, and arrives by virtue of the exec-and-friends system calls declared in unitstd.h.

I suppose the one 'gotcha' here is that you can't have a module which can both act as a program and library.  We have the similar limitations in C - we have a special object file which has a symbol named 'main' and usually load library code as DSOs - but I never really found that to be a significant limitation in real-world work.

What is an example use-case that would take advantage of this proposal?

Wes


On 19 May 2017 at 10:25, Jan Krems <[hidden email]> wrote:
Sorry, mentioning support in syntax highlighters might have been misleading. I am talking specifically about executable JavaScript scripts and modules. It's a common pattern in node to have programs written in JavaScript, with a shebang and the x flag set.

I just mentioned editor / syntax highlighter support to say "this is already de-facto part of real life JavaScript as it's understood by tools, it's just missing from the spec".

On Fri, May 19, 2017 at 1:44 AM Alexander Jones <[hidden email]> wrote:
It doesn't make any sense. The shebang is a UNIX way of declaring the interpreter for an executable script, not for hinting your syntax highlighter. If your file is not executable (as in, it can't be run with `./filename`, it shouldn't have a shebang).

On 19 May 2017 at 02:44, Jan Krems <[hidden email]> wrote:
Tried to search past proposals for this but couldn't find one The short version: Most editors / syntax highlighting engines, non-engine parsers, node.js - they all support a leading shebang line in .js files. With the advent of ES6 modules it's the final holdout where node has to patch the script source to make V8 parse the code (and thus producing a mismatch between what's on disk and what the engine sees).

Is there a downside to allow any script or module to begin with the magical #! bytes? It should not break existing scripts because it's invalid syntax today & the parse overhead should be fairly limited.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




--
Wesley W. Garland
Director, Product Development
PageMail, Inc.
<a href="tel:(613)%20542-2787" value="+16135422787" target="_blank">+1 613 542 2787 x 102

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss