Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Clarify parser error when a sourceType of “module” is expected to avo…
Browse files Browse the repository at this point in the history
…id confusion with @std/esm options.
  • Loading branch information
jdalton committed Aug 15, 2017
1 parent 53f09d0 commit 06d73f9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/acorn-ext/tolerance.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import wrap from "../util/wrap.js"

const engineDupPrefix = "Duplicate export of '"
const parserDupPrefix = "Duplicate export '"
const engineDupPrefix = "Duplicate export of '"

const parserTypePostfix = "may appear only with 'sourceType: module'"
const engineTypePostfix = "may only be used in ES modules"

function enable(parser) {
parser.raise = wrap(parser.raise, raise)
parser.raiseRecoverable = wrap(parser.raise, raiseRecoverable)
return parser
}

function raise(func, args) {
const [pos, message] = args

if (message.endsWith(parserTypePostfix)) {
func.call(this, pos, message.replace(parserTypePostfix, engineTypePostfix))
return
}

func.apply(this, args)
}

function raiseRecoverable(func, args) {
const [pos, message] = args

if (message.startsWith(parserDupPrefix)) {
func.call(this, pos, message.replace(parserDupPrefix, engineDupPrefix))
return
}

if (message.startsWith("Binding ") ||
Expand Down

0 comments on commit 06d73f9

Please sign in to comment.