babel/babylon

TypeScript: Range data missing from FunctionExpression

JamesHenry opened this issue ยท 5 comments

Hey @andy-ms!

I have begun using our prettier tests as a way of finalising the AST alignment work between typescript-eslint-parser and babylon-typescript-plugin. The overarching issue is here: prettier/prettier#2334

I have only just begun digging into it, but the first issue I noticed was that for the below code, babylon is currently not including a range: [] property on the FunctionExpression within the first then() (presumably the others as well I did not double check ๐Ÿ˜„ ). This is causing prettier to throw because it is expecting the range array to exist.

Input Code

someObject.someFunction().then(function() {
  return someObject.someFunction().then(function() {
    return someObject.someFunction().then(function() {
      return someObject.someFunction().then(function() {
        return someObject.someFunction().then(function() {
          return someObject.someFunction().then(function() {
            return someObject.someFunction().then(function() {
              return someObject.someFunction().then(function() {
                return someObject.someFunction().then(function() {
                  return someObject.someFunction().then(function() {
                    return someObject.someFunction().then(function() {
                      return someObject.someFunction().then(function() {
                        return someObject.someFunction().then(function() {
                          return someObject.someFunction().then(function() {
                            anotherFunction();
                          });
                        });
                      });
                    });
                  });
                });
              });
            });
          });
        });
      });
    });
  });
});

Babylon/Babel Configuration

{
    sourceType: "module",
    allowImportExportEverywhere: true,
    allowReturnOutsideFunction: true,
    plugins: [
      "jsx",
      "typescript",
      "doExpressions",
      "objectRestSpread",
      "decorators",
      "classProperties",
      "exportExtensions",
      "asyncGenerators",
      "functionBind",
      "functionSent",
      "dynamicImport",
      "numericSeparator"
    ]
  };

Your Environment

software version
Babylon 7.0.0-beta.16
node 7
npm 4
Operating System macOS 10.12.5
hzoo commented

Hey @JamesHenry! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

All hail robot @hzoo ๐Ÿค– ๐Ÿ˜„

Looks like inclusion of the range property is behind a flag, could you try adding it to your configuration?

Can't believe I missed that ๐Ÿ˜… thanks, @andy-ms! I'll keep you posted on the other points I find.

hzoo commented

Oh yeah we added back* ranges since it's not always necessary; #363 only added it back in to emulate acorn/for webpack test (since we don't use it in babel itself)