Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source maps #6

Open
lmiller1990 opened this issue Sep 20, 2020 · 4 comments
Open

Source maps #6

lmiller1990 opened this issue Sep 20, 2020 · 4 comments

Comments

@lmiller1990
Copy link
Owner

Add support for source maps

@lmiller1990
Copy link
Owner Author

Interesting one. So for the Hello.vue:

    tests/Hello.vue.ts:9:31 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

    9     const count = ref<string>(5)
                                    ~
    tests/Hello.vue.ts:10:23 - error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.

    10     const inc = () => count.value++
                             ~~~~~~~~~~~

Note: ts-jest says lines 9 and 10 are problems.

Looking at the source map from Vue/SFC compiler:

{
  version: 3,
  sources: [ 'component.vue' ],
  names: [],
  mappings: ';AAKA,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;EACL,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;EACf,CAAC,CAAC;AACJ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;;AAEX,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;EAC7B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;IACN,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;IAE9B,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;MACL,CAAC,CAAC,CAAC,CAAC,CAAC;MACL,CAAC,CAAC;IACJ;EACF;AACF,CAAC',
  file: 'component.vue',
  sourceRoot: '',
  sourcesContent: [
    '<template>\n' +
      '  <button @click="inc">Count: {{ count }}</button>\n' +
      '</template>\n' +
      '\n' +
      '<script lang="ts">\n' +
      'import {\n' +
      '  defineComponent,\n' +
      '  ref\n' +
      "} from 'vue'\n" +
      '\n' +
      'export default defineComponent({\n' +
      '  setup() {\n' +
      '    const count = ref<string>(5)\n' +
      '    const inc = () => count.value++\n' +
      '\n' +
      '    return {\n' +
      '      count,\n' +
      '      inc\n' +
      '    }\n' +
      '  }\n' +
      '})\n' +
      '</script>\n'
  ]
}

The error SHOULD show lines 13-14. We need to offset for the <template> I guess. Vue-jest appears to have some stuff going on which is probably for similar reasons: https://github.com/vuejs/vue-jest/blob/master/lib/generate-source-map.js.

Million dollar question here is going to be: how do we "trick" ts-jest into showing the right line numbers? Naive solution would just be appending "\n" * N to the input to ts-jest, where N is the correct offset.

What do you think @ahnpnl?

Also of interest: if we are really ambitious, we may even be able to type-check the <template>... https://twitter.com/youyuxi/status/1307398376464539648

@lmiller1990
Copy link
Owner Author

output = super.process("\n".repeat(4) + scriptResult.content, `${filePath}.ts`, jestConfig, transformOptions)

We can "trick" it. This might work!

image

@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 20, 2020

LGTM, I think this is the easiest solution we can have.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 20, 2020

Also of interest: if we are really ambitious, we may even be able to type-check the <template>... https://twitter.com/youyuxi/status/1307398376464539648

This is really nice. So if the tests pass type checking of TS, the next check is template check which will then also throw errors if something goes wrong for template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants