Skip to content

standalone.js: not ES5 compatible anymore since 1.15.0 -> Unexpected token: keyword (const) #5461

@christophercr

Description

@christophercr

Environments:

  • Prettier Version: 1.15.x
  • Running Prettier via: Webpack, UglifyJS
  • Runtime: Node.js v6, Node.js v8
  • Operating System: ALL

Steps to reproduce:

Build your application with Webpack and UglifyJS targeting ES5.

Expected behavior:
The applications should build correctly with ES5 without using any parser to compile external libraries (i.e. Prettier).

Actual behavior:
The build fails due to:

ERROR in vendor.b5330e7b0af9bd05ebf3.chunk.js from UglifyJs
Unexpected token: keyword (const) [./node_modules/prettier/standalone.js:18962,0][vendor.b5330e7b0af9bd05ebf3.chunk.js:45354,0]

The issue was introduced in this commit: 9120689#diff-863f7f2568e0a7b62f866fcadb68d31e as part of this PR #5040 for Prettier 1.15.x.

Basically, this destructuring assignment:

const {
   cjkPattern,
   kPattern,
   punctuationPattern
 } = require("./constants.evaluate");

is not correctly parsed to ES5 when building/releasing the Prettier package. In the distribution package the standalone.js file is like this:

// "const" is not ES5, but ES6 standard
const json$9 = {"cjkPattern":"[...]","kPattern":"[...]","punctuationPattern":"[...]"};

var cjkPattern = json$9.cjkPattern;
var kPattern = json$9.kPattern;
var punctuationPattern$1 = json$9.punctuationPattern;

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:standaloneIssues with Prettier's Standalone build (meant to be used in the browser)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!type:infraIssues about CI, publishing to npm, or similar

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions