Giter Site home page Giter Site logo

babel / babel Goto Github PK

View Code? Open in Web Editor NEW
42.9K 811.0 5.6K 107.85 MB

🐠 Babel is a compiler for writing next generation JavaScript.

Home Page: https://babel.dev

License: MIT License

JavaScript 30.61% Makefile 0.09% Shell 0.55% HTML 0.07% TypeScript 68.67% Batchfile 0.01%
babel javascript ast compiler flavortown es6 es2015

babel's Issues

Error: no templates directory

Error: no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/sebmck/6to5/issues

Is this a user error or a package error?

Modules Corrections

I know you're going for ease of use here, but it would be best if users get a clear consensus on modules between projects, otherwise interop suffers.

Here's the corrections I would make. No pressure at all - it is your project.

import "foo"; // var foo = require("foo");
import "foo-bar"; // var fooBar = require("foo-bar");
import "./directory/foo-bar"; // var fooBar = require("./directory/foo-bar");
import foo from "foo"; // var foo = require("foo");
import * as foo from "foo"; // var foo = require("foo");

import { bar } from "foo"; // var bar = require("foo").bar;
import foo as bar from "foo"; // var bar = require("foo").foo;

export { test }; // exports.test = test;
export var test = 5; // var test = 5; exports.test = test;

export default test; // module.exports = exports = test;

Should be

import "foo"; // require("foo");
import "foo-bar"; // require("foo-bar");
import "./directory/foo-bar"; // require("./directory/foo-bar");
import foo from "foo"; // var foo = require("foo").default;
import * as foo from "foo"; // var foo = require("foo");

import {bar} from "foo"; // var bar = require("foo").bar;
import {foo as bar} from "foo"; // var bar = require("foo").foo;

export {test}; // exports.test = test;
export var test = 5; // var test = 5; exports.test = test;

export default test; // exports.default = test;

Happy to continue the discussion. There are also variations to allow better interop with existing CommonJS if you want to dive into that topic, which I'm always happy to.

Solve issue TypeError: Object function () ... has no method 'on'

I'm preparing a gulpfile using, among others, the gulp-6to5 plugin. I'm not sure this is an issue with transpiling ... somehow it looks more of an issue with gulp streams, anyway I'm posting it here as suggested in plugin page.

When running the following gulp task (sixToFive is 'gulp-6to5'):

gulp.task('build', ['setup', 'clean', 'compile']);
[...]
gulp.task('compile', function () {
  var compress = lazypipe()
    .pipe(concat, 'all.js')
    .pipe(uglify);

  return gulp.src('src/lib/**/*.js')
    .pipe(sourcemaps.init())
    .pipe(sixToFive())
    .pipe(gulpif(config.production, compress))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest(paths.dist));
});

I got the following error:

[03:47:06] 'compile' errored after 13 ms
[03:47:06] TypeError: Object function () {
                                validateSteps(steps);
                                return combine.apply(null, steps.map(function(t) {
                                        return t.task.apply(null, t.args);
                                }));
                        } has no method 'on'
    at DestroyableTransform.Readable.pipe (..rootDir..\node_modules\gulp-6to5\node_modules\through2\node_modules\read
able-stream\lib\_stream_readable.js:516:8)
    at Gulp.gulp.task.mochaOptions.ui (..rootDir..\gulpfile.js:54:6)
    at module.exports (..rootDir..\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (..rootDir..\node_modules\gulp\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (..rootDir..\node_modules\gulp\node_modules\orchestrator\index.js:214:10)
    at ..rootDir..\node_modules\gulp\node_modules\orchestrator\index.js:279:18
    at finish (..rootDir..\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:21:8)
    at cb (..rootDir..\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:29:3)
    at Gulp.<anonymous> (..rootDir..\gulpfile.js:43:3)
    at module.exports (..rootDir..\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)

(..rootDir.. is just not to show long paths here in the post)

Transform of block scoping results in unusable code

I'm new to ES6 so I'm not sure if this is a bug or a feature.

I have this little piece of code:

function student () {
  let isStudent = true;
  return Object.freeze({
    isStudent
  });
}

6to5 transpiles it into:

function student() {
  (function () {
    var isStudent = true;
    return Object.freeze({ isStudent: isStudent });
  }());
}

whereas the Traceur and es6-transpiler output looks like:

function student () {
  var isStudent = true;
  return Object.freeze({
    isStudent: isStudent
  });
}

My problem here is that the code transpiled by 6to5 returns an undefined while the others return the desired freezed object. Now I'm curious if this is a brain or a software bug.

Using spread on super args generates invalid JS.

class Blah extends Foo {
  constructor() {
     super(...arguments);
  }
}

Generates a super call that looks like this.

Foo.call.apply(null, [this].concat(Array.prototype.slice.call(arguments)));

Currently getting around this by doing gross workarounds like this.

var s = super;
s.apply(this, arguments);

6to5/register doesn't work if writing es6 in the file in which 6to5/register is defined.

If I make a file such as:

require('6to5/register')
require('6to5/polyfill')

class A {
    constructor() {
        console.log('A')
    }
}

var a = new A()

I will get the following error:

class A {
^^^^^
SyntaxError: Unexpected reserved word
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

but if I put class A in it's own file and require it, everything work as expected.

Avoid npm WARN package.json [email protected] No README data

Not sure if we are missing something very obvious here, but each time we run a build from npm (in turn invoking gulp.js) we see this warning.

We read that this is due to the README.md not present in downloaded module, and as a matter of fact that could not be found in node_modules\6to5, but still that exists here on github repo.

Nothing serious, just a little annoying. Thanks and keep up the good work!

Can't use --out-file?

~/code/es6test β—‹ uname -rvps
Linux 3.13.0-36-generic #63-Ubuntu SMP Wed Sep 3 21:30:07 UTC 2014 x86_64
~/code/es6test β—‹ node -v
v0.10.30
~/code/es6test β—‹ npm -v
1.4.21
~/code/es6test β—‹ 6to5 -V
0.2.0
~/code/es6test β—‹ npm install -g sebmck/6to5
/usr/local/bin/6to5 -> /usr/local/lib/node_modules/6to5/bin/6to5
/usr/local/bin/6to5-node -> /usr/local/lib/node_modules/6to5/bin/6to5-node
[email protected] /usr/local/lib/node_modules/6to5
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected] ([email protected])
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected] ([email protected])
β”œβ”€β”€ [email protected]
└── [email protected] ([email protected], [email protected], [email protected], [email protected])
~/code/es6test β—‹ echo "[1, 2, 3].map(x => x * x)" > test.js
~/code/es6test β—‹ 6to5 test.js 
[
  1,
  2,
  3
].map(function (x) {
  return x * x;
});


~/code/es6test β—‹ 6to5 test.js --out-file compiled-test.js

fs.js:432
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
TypeError: path must be a string
    at Object.fs.openSync (fs.js:432:18)
    at Object.fs.writeFileSync (fs.js:971:15)
    at Object.<anonymous> (/usr/local/lib/node_modules/6to5/bin/6to5:139:8)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

Source map always blank

var to5 = require('6to5');
var result = to5.transform('let foo = {bar: "baz"};\n var {bar} = foo;', {filename:'foo.js',sourceMap: true});
var sourceMap = result.split('\n').splice(-2, 1)[0].slice(50);
console.log((new Buffer(sourceMap, 'base64')).toString());
// {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}

super() without explicit method name should use current method

class A { toString() { return 'a'; } }
class B extends A { toString() { return 'b(' + super() + ')'; } }
console.log(new B().toString());

This should print b(a), but right now it prints b(undefined) because super() turns into A.call(this) when this would be closer: A.prototype.toString.call(this).

Path Disappears in Source Map?

Probably a noob question since I'm a novice with source maps. When I pass in a path+file to options.filename, (ex: /app/script/test.js) while generating source maps, the source map has sources[0] set to test.js and sourceRoot is not defined, meaning that information on the path is nowhere. Shouldn't it appear or able to be inferred somehow? (full path on sources[0] or directory in sourceRoot) I haven't seen this problem with other source maps.

Simplify source map options

Could be just one option.

Instead of:

// Append source map and comment to bottom of returned output.
  sourceMap: false,

  // Returns an object `{ code: "", map: {} }` instead of an appended string.
  sourceMapObject: false,

You could have:

sourceMap: 'inline',
sourceMap: 'external', // or a better word?
sourceMap: false

Issue with computed properties?

// foo.js
var obj = {
  ["x" + foo]: "heh",
  ["y" + bar]: "noo",
  foo: "foo",
  bar: "bar"
};

$ 6to5 foo.js

var obj = function (obj) {
  obj['x' + foo] = 'heh';
  obj['y' + bar] = 'noo';
  return obj;
}({
  foo: 'foo',
  bar: 'bar'
});

That would result in: ReferenceError: foo is not defined

It should have been:

var obj = function (obj) {
  obj['x' + obj.foo] = 'heh';
  obj['y' + obj.bar] = 'noo';
  return obj;
}({
  foo: 'foo',
  bar: 'bar'
});

TypeError: Cannot read property 'prototype' of undefined

I get the following error:

TypeError: Cannot read property 'prototype' of undefined

when I make a file with the following:

require('6to5/register')
require('6to5/polyfill')

var Collection = require('./lib/collection')

var collection = new Collection()

and in ./lib/collection:

var Backbone = require('backbone')

class Collection extends Backbone.Collection {

  initialize() {
    super()

  }

}

module.exports = Collection

If I don't call super, there's no error.

If I rename the class I'm extending to BackboneCollection like so:

var Backbone = require('backbone'),
BackboneCollection = Backbone.Collection

class Collection extends BackboneCollection {

  initialize() {
    super()

  }

}

module.exports = Collection

it works fine.

Assuming this is related to the error I ran into the other day? #22

missing templates when installed via npm

npm install sebmck/6to5

Ξ» node
> to5 = require('6to5')
Error: ENOENT, no such file or directory '/Code/6to5test/node_modules/6to5/lib/6to5/templates'
    at Object.fs.readdirSync (fs.js:654:18)
    at Object.<anonymous> (/Code/6to5test/node_modules/6to5/lib/6to5/util.js:201:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Code/6to5test/node_modules/6to5/lib/6to5/transform.js:4:16)
    at Module._compile (module.js:456:26)

https://github.com/sebmck/6to5/blob/master/.npmignore#L5

Seems as if your intention is to only include them for dev/test, but util needs to be fixed to not puke when they're absent.

Destructuring assignment inside function arguments

6to5 (awesome project btw) cannot process the following snippets:

function unpackObject({title: title, author: author}) {
  return title + ' ' + author;
}
console.log(unpackObject({title: 'title', author: 'author'});

function unpackArray([a, b, c]) {
  return a+b+c;
}
console.log(unpackArray(['hello', ', ', 'world']));

Any idea if it's possible to support that?

Source map missing file property

Even though I specified filename in options.

_file: undefined,

Reproduce: Run npm test in the gulp-6to5 repo. https://github.com/sindresorhus/gulp-6to5/blob/e7bd9167c7ba3d98f521fa675b026511965f7af6/index.js#L30

Full map:

{ _file: undefined,
  _sourceRoot: null,
  _sources: { _array: [ 'fixture.js' ], _set: { '$fixture.js': 0 } },
  _names: { _array: [ 'map', 'v' ], _set: { '$map': 0, '$v': 1 } },
  _mappings: 
   [ { generatedLine: 1,
       generatedColumn: 0,
       originalLine: 1,
       originalColumn: 0,
       source: 'fixture.js',
       name: null },
     { generatedLine: 1,
       generatedColumn: 3,
       originalLine: 1,
       originalColumn: 3,
       source: 'fixture.js',
       name: 'map' },
     { generatedLine: 1,
       generatedColumn: 6,
       originalLine: 1,
       originalColumn: 0,
       source: 'fixture.js',
       name: null },
     { generatedLine: 1,
       generatedColumn: 7,
       originalLine: 1,
       originalColumn: 7,
       source: 'fixture.js',
       name: null },
     { generatedLine: 1,
       generatedColumn: 17,
       originalLine: 1,
       originalColumn: 7,
       source: 'fixture.js',
       name: 'v' },
     { generatedLine: 1,
       generatedColumn: 18,
       originalLine: 1,
       originalColumn: 7,
       source: 'fixture.js',
       name: null },
     { generatedLine: 1,
       generatedColumn: 20,
       originalLine: false,
       originalColumn: false,
       source: null,
       name: null },
     { generatedLine: 2,
       generatedColumn: 9,
       originalLine: 1,
       originalColumn: 12,
       source: 'fixture.js',
       name: 'v' },
     { generatedLine: 2,
       generatedColumn: 10,
       originalLine: 1,
       originalColumn: 12,
       source: 'fixture.js',
       name: null },
     { generatedLine: 2,
       generatedColumn: 13,
       originalLine: 1,
       originalColumn: 16,
       source: 'fixture.js',
       name: null },
     { generatedLine: 2,
       generatedColumn: 14,
       originalLine: false,
       originalColumn: false,
       source: null,
       name: null },
     { generatedLine: 3,
       generatedColumn: 1,
       originalLine: 1,
       originalColumn: 0,
       source: 'fixture.js',
       name: null } ],
  _sourcesContents: { '$fixture.js': '[].map(v => v + 1)' } }

Consistent return value

It's weird that the output type can change based on an option.

  // Returns an object `{ code: "", map: {} }` instead of an appended string.
  sourceMapObject: false,

I think you should always return an object. Just make the .map prop null when sourceMapObject: false.

block-level let compliation

compilation of the following code

(function() {
    if(true){
        let a = arguments[0];
        console.log(a);
    }
})(1);

will turn into:

(function() {
        if(true){
        (function() {
            var a = arguments[0];
            console.log(a);
        })();
    }
})(1);

which is incorrect.

Assigning class properties

How should I assign properties on a class?

I tried this:

class Blah {

  foo: 'bar'

  constructor() {
    console.log(this.foo)
  }

}

but got an error about Unexpected string on foo: 'bar'.

I assumed assigning class properties would be the same as CoffeeScript, where foo is placed on the prototype of Blah.

I can do either of the following, but neither are as much fun:

Approach A

class Blah {
  constructor() {
    this.foo = 'bar'
    console.log(this.foo)
  }

}

The problem with this approach is that I cannot use Blah.prototype.foo to override the default value.

Approach B

class Blah {
  constructor() {
    console.log(this.foo)
  }

}

Blah.prototype.foo = 'bar'

The "problem" with this approach is that it requires assigning default values outside the class declaration.

Extending class fails

When saying

class BaseController extends Chaplin.Controller

I get the following error:

{ '0': 
{ [Error: Parsing file /Projects/app/controllers/base/controller.js: Line 2: Unexpected token .]
 stream: 
  { _readableState: [Object],
    readable: true,
    domain: null,
    _events: [Object],
    _maxListeners: 10,
    _writableState: [Object],
    writable: true,
    allowHalfOpen: true,
    _options: [Object],
    _wrapOptions: [Object],
    _streams: [Object],
    length: 1,
    label: 'deps' } } }

This does not work either:

class BaseController extends Chaplin['Controller']

module bindings with immediate cycles do not work

This is, admittedly, a use case that is rare in the CommonJS world. However it is a valid ES6 modules use case. In this example there is a cycle between evens.js and odds.js that should nevertheless work. This example is taken from the es6-module-transpiler test suite.

// odds.js

import { isEven } from './evens';

export function nextOdd(n) {
  return isEven(n) ? n + 1 : n + 2;
}

/**
 * We go through these gymnastics to eager-bind to isEven. This is done to
 * ensure that both this module and the 'evens' module eagerly use something
 * from the other.
 */
export var isOdd = (function(isEven) {
  return function(n) {
    return !isEven(n);
  };
})(isEven);



// evens.js
import { nextOdd } from './odds';

/**
 * We go through these gymnastics to eager-bind to nextOdd. This is done to
 * ensure that both this module and the 'odds' module eagerly use something
 * from the other.
 */
export var nextEven = (function() {
  return function(n) {
    var no = nextOdd(n);
    return (no === n + 2) ?
      no - 1 : no;
  };
})(nextOdd);

export function isEven(n) {
  return n % 2 === 0;
}



// main.js
/**
 * The 'evens' and 'odds' modules are configured in such a way that they both
 * have two exported functions: isEven, nextEven, isOdd, and nextOdd. Normally
 * these four functions could be in any order regardless of which depends on
 * which because of JavaScript function hoisting.
 *
 * For the purposes of our test we need to prevent function hoisting, so it has
 * been arranged that two of them will be function expressions assigned to
 * variables. Specifically, isOdd and nextEven both eagerly evaluate their
 * dependencies (i.e. isEven and nextOdd). This allows us to test that exported
 * function declarations are available before what would be a module's
 * "execute" step, per the spec.
 */
import { nextEven, isEven } from './evens';
import { nextOdd, isOdd } from './odds';

assert.equal(nextEven(1), 2);
assert.equal(nextOdd(1), 3);
assert.ok(isOdd(1));
assert.ok(!isOdd(0));
assert.ok(isEven(0));
assert.ok(!isEven(1));

The way we handle this in the es6-module-transpiler is to export function declarations at the top of the module scope before any requires. So where right now this project converts odds.js to this:

var isEven = require('./evens').isEven;
function nextOdd(n) {
  return isEven(n) ? n + 1 : n + 2;
}

exports.nextOdd = nextOdd;
var isOdd = (function(isEven) {
  return function(n) {
    return !isEven(n);
  };
})(isEven);
exports.isOdd = isOdd;

It should convert it to this:

exports.nextOdd = nextOdd;

var isEven = require('./evens').isEven;
function nextOdd(n) {
  return isEven(n) ? n + 1 : n + 2;
}

var isOdd = (function(isEven) {
  return function(n) {
    return !isEven(n);
  };
})(isEven);
exports.isOdd = isOdd;

Multiple arrow functions doesn't work

Case:

module.exports = {
    init() {
        return new Promise((resolve, reject) => {
            MongoClient.connect(config.mongodb, (err, db) => {
                if (err) {
                    return reject(err);
                }
                this.db = db;
                resolve(this);
            });
        });
    }
}

Compiles to:

module.exports = {
    init: function() {
        return new Promise(function(resolve, reject) {
            var _this = this;
            MongoClient.connect(config.mongodb, function(err, db) {
                if (err) {
                    return reject(err);
                }
                _this.db = db;
                resolve(_this);
            });
        });
    }
}

var _this = this; should be on the line after init: function() { ?

module syntax ?

I were using traceur that support the module thing from "stuff" syntax that we can found here.
http://wiki.ecmascript.org/doku.php?id=harmony:modules
I've tried to replace that by import * as thing from "stuff" but my prior transformation (reactify (jsx)) is now broken (probably unable to parse).
Why don't your handle this syntax too ?

Add support for hash bangs

For example, running 6to5 on the following code currently raises an exception:

#!/usr/bin/env node

console.log(3);

Maybe I'm just lost...but I can't get this to compile at all

I ran this example command:

$ 6to5 script.js --out-file script-compiled.js

script.js included the following:

var BaseView = class BaseView {
  constructor() {
    this.autoRender = true;
  }
}

module.exports = BaseView

but script-compiled.js ended up being the exact same thing. There was no compilation.

Using 6to5-node with forever - problem resolving path

When running the 6to5-node script using forever.js (to keep node instances running), the filenames provided by forever (commander.args) have their paths resolved, so doing a path.join(process.cwd(),filename) should only be done if filename.charAt(0) != '/', or node will be unable to find the desired file (the path will have been resolved twice).

To fix, I replace the require() line with:
require(require.resolve(filename.charAt(0) == '/' ? filename : path.join(process.cwd(),filename)));

super in class static methods tries to call prototype method

class A {
  static foo() {
    return 'A#foo';
  }
}

class B extends A {
  static foo() {
    return 'B#foo, ' + super();
  }
}

console.log(B.foo());

This should print B#foo, A#foo but it currently throws an exception trying to access A.prototype.foo.call.

'Illegal return statement' when using let

In certain circumstances, the transformed code looks like this:

return function () {
  /* code goes here */
}();

This causes an 'Illegal return statement' syntax error. It appears to be caused by some combination of let and functions. These all work...

let _message = 'hello';
console.log( _message );
console.log( message() );

function message () {
  return 'hello';
}
var _message = message();
console.log( _message );

function message () {
  return 'hello';
}

...but this doesn't:

let _message = message();
console.log( _message );

function message () {
  return 'hello';
}

It transforms to this:

return function() {
  var _message = message();
  console.log( _message );

  function message () {
    return 'hello';
  }
}();

Source maps stopped populating `names` in [email protected]

Source map from 1.6.0:

{"version":3,"sources":["fixture.js"],"names":["Test"],"mappings":"IAAMA,I;WAAAA,I;;SAAAA,I","file":"fixture.js","sourcesContent":["class Test {}\n"]}

Source map from 1.7.0:

{"version":3,"file":"fixture.js","sources":["fixture.js"],"names":[],"mappings":"IAAM,CAAC,CAAC,CAAC;WAAH,CAAC,CAAC,CAAC;SAAH,CAAC,CAAC,CAAC","sourcesContent":["class Test {}\n"]}

Appears to be a side effect from the switch to recast. Might not be important, but I figured I'd report it.

6to5-node throw error

$ npm install -g 6to5
$ 6to5-node

module.js:340
    throw err;
          ^
Error: Cannot find module 'es6-symbol/implement'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/azu/.nodebrew/node/v0.10.28/lib/node_modules/6to5/lib/6to5/polyfill.js:1:63)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

Env:

$ node -v
v0.10.28
$ npm -v
2.1.2

Workaround :

npm install -g  es6-symbol

It may be as well to add es6-symbol to dependencies of package.json.

Browser support

it would be amazing to be able to run this in the browser. Is the only thing preventing that from happening the node 'fs' calls?

If that's all it is, I could pull request a browser version if you'd like.

rest params do not work in class constructor methods

> class A { constructor(...args) { console.log(args) } }
undefined
> new A(1, 2, 3)
ReferenceError: args is not defined
    at new A (repl:2:30)
    at repl:1:5
    at REPLServer.replEval [as eval] (6to5/bin/6to5-node:63:17)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.emit (events.js:98:17)

This should result in a function A that immediately logs the arguments given to it as an array.

class methods should not be enumerable

This is not that big a deal as most code probably will not depend on this, but file this away somewhere under "spec compliance".

class A {
  foo() {}
}

for (var key in new A()) {
  console.log(key);
}

This should print nothing, but it currently prints foo.

class definition doesn't care constants.

When I write

const X = 1;
var X = 2;

It gives me an error that X is read-only.

If I define X as a class, it changes X.

const X = 1;
class X {
  constructor() {}
}

It changes the X instead of throwing X is read-only error.

Extending class constructor doesn't work

class A {
    constructor(name) {
        this.name = name;
    }
}

class B extends A {
    hello() {
        return 'Hello ' + this.name;
    }
}

var b = new B('John');
require('assert').equal('Hello John', b.hello());

The output is :

var A = function() {
    function A(name) {
        this.name = name;
    }

    return A;
}();

var B = function(A) {
    function B() {
        A.call(this, arguments);
    }

    B.prototype = Object.create(A.prototype, {
        constructor: {
            value: B,
            enumerable: false,
            writable: true,
            configurable: true
        }
    });

    B.__proto__ = A;

    B.prototype.hello = function() {
        return 'Hello ' + this.name;
    };

    return B;
}(A);

var b = new B('John');
require('assert').equal('Hello John', b.hello());

A.call(this, arguments); should be A.apply(this, arguments); ?

Cannot find module 'source-map'

Just tried this out in the command line and get the following error from lib/6to5/transform.js with 1.7.6:

$ npm install 6to5
...
$ node
> require('6to5')
Error: Cannot find module 'source-map'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.