Skip to content

Commit

Permalink
fix(typescript): use empty string when sourceMapText is undefined (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchaser53 authored and eddyerburgh committed Mar 14, 2018
1 parent 9b26acd commit 87d1049
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/compilers/typescript-compiler.js
Expand Up @@ -52,6 +52,9 @@ module.exports = function compileTypescript (scriptContent) {
const tsConfig = getTypescriptConfig()

const res = typescript.transpileModule(scriptContent, tsConfig)
const inputSourceMap = (res.sourceMapText !== undefined)
? JSON.parse(res.sourceMapText)
: ''

// handle ES modules in TS source code in case user uses non commonjs module
// output and there is no .babelrc.
Expand All @@ -64,5 +67,5 @@ module.exports = function compileTypescript (scriptContent) {
}
}

return compileBabel(res.outputText, JSON.parse(res.sourceMapText), inlineBabelConfig)
return compileBabel(res.outputText, inputSourceMap, inlineBabelConfig)
}
21 changes: 20 additions & 1 deletion test/TypeScript.spec.js
Expand Up @@ -2,7 +2,7 @@ import { shallow } from 'vue-test-utils'
import { resolve } from 'path'
import TypeScript from './resources/TypeScript.vue'
import jestVue from '../vue-jest'
import { readFileSync, renameSync } from 'fs'
import { readFileSync, renameSync, writeFileSync } from 'fs'
import cache from '../lib/cache'

beforeEach(() => {
Expand All @@ -28,3 +28,22 @@ test.skip('generates inline sourcemap', () => {
const output = jestVue.process(fileString, filePath)
expect(output).toContain(expectedMap)
})

test('processes without sourcemap', () => {
const configPath = resolve(__dirname, '../tsconfig.json')
const tsconfigString = readFileSync(configPath, { encoding: 'utf8' })
const tsconfig = JSON.parse(tsconfigString)
tsconfig.compilerOptions.sourceMap = false
writeFileSync(configPath, JSON.stringify(tsconfig))
const filePath = resolve(__dirname, './resources/TypeScript.vue')
const fileString = readFileSync(filePath, { encoding: 'utf8' })

try {
expect(() => jestVue.process(fileString, filePath)).not.toThrow()
} catch (err) {
writeFileSync(configPath, tsconfigString)
throw err
}

writeFileSync(configPath, tsconfigString)
})

0 comments on commit 87d1049

Please sign in to comment.