package keyword reserved?

# Jonathan Bond-Caron (11 years ago)

What's the history of the unused keyword "package", is it from Java?

Been thinking about this lately, could an external module be called a package?

package/file.js
package "something" {
  export class foo {}
}

package "other" {
  export class foo {}

 export module bar {
        export class foo {}
   }
}

import {foo as a} from "something"
import {foo as b, bar.foo} from "other"

/* option a) */
var api = {
   foo: a,
   fooOther: b,
   fooBar: bar.foo
   hello: function() {  alert('module') };
}

export default api

/*  option b) single module declaration
module apiInternalName {
  import {foo} from "something"
  import {foo as fooOther, bar.foo as fooBar} from "other"
  function hello() {  alert('module') };
}
*/

single/file.js
module barInternalName {
  class foo {}
}

main.js
module api from 'package/file'
module bar from 'single/file'

Some thoughts:

  •       Literal modules are allowed only within packages (no module nesting) or a single module per file
    
  •       import() semantics don't change too much (I think)
    
  •       The subtle difference is an internal module is the declaration mechanism for exporting an api, a package is used for code organisation.
    
  •       The module pattern is optional, can import from packages directly :
    
index.html
<script src="package/file.js"></script>
<script>
    // import from package
    import {foo, bar} from "other";
</script>
# Domenic Denicola (11 years ago)

What use cases does this solve?

# Brendan Eich (11 years ago)

Jonathan Bond-Caron wrote:

What’s the history of the unused keyword “package”, is it from Java?

In 1995, I reserved all the Java (JDK1.0 era) reserved identifiers.

ES1 kept them, but ES5 cut way back, yet kept 'package' among others as reserved in strict code. No one had a championed proposal for 'package', though. It was reserved along with others because "it seemed like a better idea than unreserving".

Please don't rush to contrive a use for 'package' without a use-case.

# Jonathan Bond-Caron (11 years ago)

On Fri Apr 11 05:25 PM, Domenic Denicola wrote:

What use cases does this solve?

Struggling with Typescript's mixed module definition.

a) module name {}

Or

b) module "name" {}

Painful to make a decision about either syntax, started with (a) which isn't Ecma :/

# Domenic Denicola (11 years ago)

What use cases does this solve for JavaScript, not TypeScript?

# Jonathan Bond-Caron (11 years ago)

Not sure, benefit comes down to subjective preference. Keeps the single 'module' per file pattern from node.js

Is it safe to use the 'package' keyword then, no proposals for using it?

# Rick Waldron (11 years ago)

On Fri, Apr 11, 2014 at 6:23 PM, Jonathan Bond-Caron <jbondc at gdesolutions.com> wrote:

Keeps the single 'module' per file pattern from node.js

This is already the case for ES6 modules, without eating up another reserved word.

# Brendan Eich (11 years ago)

Jonathan Bond-Caron wrote:

Is it safe to use the 'package' keyword then, no proposals for using it?

You mean for some other language compiled to JS to use 'package'? If so, then no: it's unsafe, explicitly so. The 'package' identifier is a strict future reserved word. Steer clear, the TC39 standards body may yet define it.