Home / File/ codeframe.spec.ts — vue Source File

codeframe.spec.ts — vue Source File

Architecture documentation for codeframe.spec.ts, a typescript file in the vue codebase. 1 imports, 0 dependents.

File typescript 1 imports

Entity Profile

Dependency Diagram

graph LR
  49d2d75a_4c2d_1470_ce22_199df202ae80["codeframe.spec.ts"]
  8f91fc21_609b_f366_8240_174566302760["codeframe"]
  49d2d75a_4c2d_1470_ce22_199df202ae80 --> 8f91fc21_609b_f366_8240_174566302760
  style 49d2d75a_4c2d_1470_ce22_199df202ae80 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { generateCodeFrame } from 'compiler/codeframe'

describe('codeframe', () => {
  const source = `
<div>
  <template key="one"></template>
  <ul>
    <li v-for="foobar">hi</li>
  </ul>
  <template key="two"></template>
</div>
    `.trim()

  it('line near top', () => {
    const keyStart = source.indexOf(`key="one"`)
    const keyEnd = keyStart + `key="one"`.length
    expect(generateCodeFrame(source, keyStart, keyEnd)).toBe(
      `
1  |  <div>
2  |    <template key="one"></template>
   |              ^^^^^^^^^
3  |    <ul>
4  |      <li v-for="foobar">hi</li>
    `.trim()
    )
  })

  it('line in middle', () => {
    // should cover 5 lines
    const forStart = source.indexOf(`v-for=`)
    const forEnd = forStart + `v-for="foobar"`.length
    expect(generateCodeFrame(source, forStart, forEnd)).toBe(
      `
2  |    <template key="one"></template>
3  |    <ul>
4  |      <li v-for="foobar">hi</li>
   |          ^^^^^^^^^^^^^^
5  |    </ul>
6  |    <template key="two"></template>
    `.trim()
    )
  })

  it('line near bottom', () => {
    const keyStart = source.indexOf(`key="two"`)
    const keyEnd = keyStart + `key="two"`.length
    expect(generateCodeFrame(source, keyStart, keyEnd)).toBe(
      `
4  |      <li v-for="foobar">hi</li>
5  |    </ul>
6  |    <template key="two"></template>
   |              ^^^^^^^^^
7  |  </div>
    `.trim()
    )
  })

  it('multi-line highlights', () => {
    const source = `
<div attr="some
  multiline
attr
">
</div>
    `.trim()

    const attrStart = source.indexOf(`attr=`)
    const attrEnd = source.indexOf(`">`) + 1
    expect(generateCodeFrame(source, attrStart, attrEnd)).toBe(
      `
1  |  <div attr="some
   |       ^^^^^^^^^^
2  |    multiline
   |  ^^^^^^^^^^^
3  |  attr
   |  ^^^^
4  |  ">
   |  ^
    `.trim()
    )
  })
})

Dependencies

  • codeframe

Frequently Asked Questions

What does codeframe.spec.ts do?
codeframe.spec.ts is a source file in the vue codebase, written in typescript.
What does codeframe.spec.ts depend on?
codeframe.spec.ts imports 1 module(s): codeframe.
Where is codeframe.spec.ts in the architecture?
codeframe.spec.ts is located at test/unit/modules/compiler/codeframe.spec.ts (directory: test/unit/modules/compiler).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free