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

Remove the dynamic require() call in the standalone bundle #5612

Merged
merged 4 commits into from
Dec 11, 2018

Conversation

j-f1
Copy link
Member

@j-f1 j-f1 commented Dec 9, 2018

Prettier will now throw an error if it can’t find the parser in the parsers object.

Fixes #4959.

  • I’ve added tests to confirm my change works. ❓ How should I test this (if at all)?
  • I’ve read the contributing guidelines.

Try the playground for this PR

locEnd
};
} catch (err) {
if (process.env.PRETTIER_TARGET !== "universal") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about an early exit with BUNDLE_TARGET !== "node"?

if (process.env.BUNDLE_TARGET !== "node") {
  throw ...
}

try { ... }
catch (...) { ... }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, that doesn’t work:

// built standalone.js
if (typeof opts.parser === "string") {
  if (parsers.hasOwnProperty(opts.parser)) {
    return parsers[opts.parser];
  }
  /* istanbul ignore next */

  {
    throw new ConfigError$1(
     "Couldn't resolve parser \"".concat(
        opts.parser,
        '". Parsers must be explicitly added to the standalone bundle.'
      )
    );
  }

  try {
    return {
      parse: require(path.resolve(process.cwd(), opts.parser)),
      astFormat: "estree",
      locStart: locStart,
      locEnd: locEnd
    };
  } catch (err) {
    /* istanbul ignore next */
    throw new ConfigError$1(
      "Couldn't resolve parser \"".concat(opts.parser, '"')
    );
  }
}

src/main/parser.js Outdated Show resolved Hide resolved
@j-f1 j-f1 merged commit b74f94d into prettier:master Dec 11, 2018
@j-f1 j-f1 deleted the remove-dynamic-require branch December 11, 2018 11:03
@ikatyang ikatyang added this to the 1.16 milestone Jan 9, 2019
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Apr 9, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Apr 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants