Skip to content

Commit

Permalink
fix: revert "load sourcemaps alongside modules (#11576)" (#11775)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Jan 20, 2023
1 parent b35fe88 commit 697dd00
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { transformRequest } from '../server/transformRequest'
import type { InternalResolveOptionsWithOverrideConditions } from '../plugins/resolve'
import { tryNodeResolve } from '../plugins/resolve'
import { genSourceMapUrl } from '../server/sourcemap'
import {
ssrDynamicImportKey,
ssrExportAllKey,
Expand All @@ -26,16 +25,6 @@ interface SSRContext {

type SSRModule = Record<string, any>

// eslint-disable-next-line @typescript-eslint/no-empty-function
const AsyncFunction = async function () {}.constructor as typeof Function
let fnDeclarationLineCount = 0
{
const body = '/*code*/'
const source = new AsyncFunction('a', 'b', body).toString()
fnDeclarationLineCount =
source.slice(0, source.indexOf(body)).split('\n').length - 1
}

const pendingModules = new Map<string, Promise<SSRModule>>()
const pendingImports = new Map<string, string[]>()

Expand Down Expand Up @@ -192,27 +181,17 @@ async function instantiateModule(
}
}

let sourceMapSuffix = ''
if (result.map) {
const moduleSourceMap = Object.assign({}, result.map, {
// offset the first three lines of the module (function declaration and 'use strict')
mappings: ';'.repeat(fnDeclarationLineCount + 1) + result.map.mappings,
})
sourceMapSuffix =
'\n//# sourceMappingURL=' + genSourceMapUrl(moduleSourceMap)
}

try {
// eslint-disable-next-line @typescript-eslint/no-empty-function
const AsyncFunction = async function () {}.constructor as typeof Function
const initModule = new AsyncFunction(
`global`,
ssrModuleExportsKey,
ssrImportMetaKey,
ssrImportKey,
ssrDynamicImportKey,
ssrExportAllKey,
'"use strict";\n' +
result.code +
`\n//# sourceURL=${mod.url}${sourceMapSuffix}`,
'"use strict";' + result.code + `\n//# sourceURL=${mod.url}`,
)
await initModule(
context.global,
Expand Down

0 comments on commit 697dd00

Please sign in to comment.