next.js/test/e2e/webpack-loader-parse-error/broken-js-loader.js
broken-js-loader.js24 lines778 B
// A webpack loader that returns invalid JavaScript with a source map.
// The source map points back to the original file, but the generated
// code is intentionally broken (unparseable).
module.exports = function (source) {
  // Generate a source map that maps back to the original source
  const sourceMap = {
    version: 3,
    sources: [this.resourcePath],
    sourcesContent: [source],
    // identity mapping: each generated line maps to the same original line
    mappings: 'AAAA;AACA;AACA;AACA',
    names: [],
  }

  // Return broken JavaScript that will fail to parse
  const brokenCode = `// Generated by broken-js-loader
export default function Page() {
  return <div>this is intentionally broken {{{ invalid jsx
}
`

  this.callback(null, brokenCode, sourceMap)
}
Quest for Codev2.0.0
/
SIGN IN