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

Native Require Support #46

Open
alongubkin opened this issue Nov 18, 2014 · 4 comments
Open

Native Require Support #46

alongubkin opened this issue Nov 18, 2014 · 4 comments

Comments

@alongubkin
Copy link
Owner

Add native require support to Spider.

Proposed Syntax

require "util"

require (
  "vm",
  "lodash" as _,
  "jashkenas/backbone" // GitHub repo
)

is compiled to:

var util = require("util"),
    vm = require("vm"),
    _ = require("lodash"),
    backbone = require("backbone"); // after the compiler automatically installs the package

The require statement would also automatically use the added identifier so there's no need for :: and use.

Problems

  • How does this work in the Browser?
  • How to combine this with ES6 modularisation features?
  • Should we use DuoJS by default (which solves the first issue)?
@zekesonxx
Copy link
Contributor

I think forcing users into using Spider's package system would be bad. What about having it default to compiling to var as = require('package'), and then allowing it to be overridden.

For example:

require 'util'

defaults to

var util = require('util');

but adding --require="var %a = duojs('%s');" results in

var util = duojs('util');

or --require="document.write('%s as %a');" results in

document.write('util as util');

@nmn
Copy link

nmn commented Dec 1, 2014

Isn't this problem solved by ES6 modules syntax?

@alongubkin
Copy link
Owner Author

This was proposed before adding ES6 modules to the language. The reason I'm not closing this yet is because I still feel CommonJS support is necessary

@nmn
Copy link

nmn commented Dec 2, 2014

Maybe this is a feature for the cli rather than for syntax? ES6 module syntax can just be transpired into Cjs?

Too many module syntax's = confusion.

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

No branches or pull requests

3 participants