• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Siubaak / sval / 14771539826

01 May 2025 07:10AM UTC coverage: 73.748% (+8.3%) from 65.487%
14771539826

push

github

Siubaak
[update] rollup -> vite

753 of 922 branches covered (81.67%)

Branch coverage included in aggregate %.

60 of 60 new or added lines in 12 files covered. (100.0%)

358 existing lines in 15 files now uncovered.

2545 of 3550 relevant lines covered (71.69%)

932.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.14
/src/evaluate/pattern.ts
1
import { NOINIT, DEADZONE } from '../share/const.ts'
1✔
2
import { VarKind } from '../scope/variable.ts'
3
import { Identifier } from './identifier.ts'
1✔
4
import { assign } from '../share/util.ts'
1✔
5
import { pattern } from './helper.ts'
1✔
6
import Scope from '../scope/index.ts'
7
import evaluate from './index.ts'
1✔
8
import * as acorn from 'acorn'
9

10
export interface PatternOptions {
11
  kind?: VarKind
12
  hoist?: boolean
13
  onlyBlock?: boolean
14
  feed?: any
15
}
16

17
export function* ObjectPattern(node: acorn.ObjectPattern, scope: Scope, options: PatternOptions = {}) {
1✔
18
  const { kind = 'var', hoist = false, onlyBlock = false, feed = {} } = options
16✔
19
  const fedKeys: string[] = []
16✔
20
  for (let i = 0; i < node.properties.length; i++) {
16✔
21
    const property = node.properties[i]
16✔
22
    if (hoist) {
16✔
23
      if (onlyBlock || kind === 'var') {
8✔
24
        if (property.type === 'Property') {
8✔
25
          const value = property.value
7✔
26
          if (value.type === 'Identifier') {
7✔
27
            scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined)
4✔
28
          } else {
7✔
29
            yield* pattern(value, scope, { kind, hoist, onlyBlock })
3✔
30
          }
3✔
31
        } else {
8✔
32
          yield* RestElement(property, scope, { kind, hoist, onlyBlock })
1✔
33
        }
1✔
34
      }
8✔
35
    } else if (property.type === 'Property') {
8✔
36
      let key: string
7✔
37
      if (property.computed) {
7!
38
        key = yield* evaluate(property.key, scope)
×
39
      } else {
7✔
40
        key = (property.key as acorn.Identifier).name
7✔
41
      }
7✔
42
      fedKeys.push(key)
7✔
43
      
44
      const value = property.value
7✔
45
      if (value.type === 'Identifier') {
7✔
46
        scope[kind](value.name, feed[key])
4✔
47
      } else {
4✔
48
        yield* pattern(value, scope, { kind, feed: feed[key] })
3✔
49
      }
3✔
50
    } else {
8✔
51
      const rest = assign({}, feed)
1✔
52
      for (let i = 0; i < fedKeys.length; i++) delete rest[fedKeys[i]]
1!
53
      yield* RestElement(property, scope, { kind, feed: rest })
1✔
54
    }
1✔
55
  }
16✔
56
}
16✔
57

58
export function* ArrayPattern(node: acorn.ArrayPattern, scope: Scope, options: PatternOptions = {}) {
1✔
59
  const { kind, hoist = false, onlyBlock = false, feed = [] } = options
8✔
60
  const result = []
8✔
61
  for (let i = 0; i < node.elements.length; i++) {
8✔
62
    const element = node.elements[i]
8✔
63
    if (!element) continue // for the case: let [ , x] = [1, 2]
8!
64
    if (hoist) {
8✔
65
      if (onlyBlock || kind === 'var') {
4✔
66
        if (element.type === 'Identifier') {
4✔
67
          scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined)
2!
68
        } else {
2✔
69
          yield* pattern(element, scope, { kind, hoist, onlyBlock })
2✔
70
        }
2✔
71
      }
4✔
72
    } else if (element.type === 'Identifier') {
4✔
73
      if (kind) {
2✔
74
        // If kind isn't undefined, it's a declaration
75
        scope[kind](element.name, feed[i])
2✔
76
      } else {
2!
77
        // If kind is undefined, it's a statement
78
        const variable = yield* Identifier(element, scope, { getVar: true })
×
79
        variable.set(feed[i])
×
80
        result.push(variable.get())
×
UNCOV
81
      }
×
82
    } else if (element.type === 'RestElement') {
2✔
83
      yield* RestElement(element, scope, { kind, feed: feed.slice(i) })
2✔
84
    } else {
2!
85
      yield* pattern(element, scope, { kind, feed: feed[i] })
×
UNCOV
86
    }
×
87
  }
8✔
88
  if (result.length) {
8!
89
    return result
×
UNCOV
90
  }
×
91
}
8✔
92

93
export function* RestElement(node: acorn.RestElement, scope: Scope, options: PatternOptions = {}) {
1✔
94
  const { kind, hoist = false, onlyBlock = false, feed = [] } = options
6✔
95
  const arg = node.argument
6✔
96
  if (hoist) {
6✔
97
    if (onlyBlock || kind === 'var') {
3✔
98
      if (arg.type === 'Identifier') {
3✔
99
        scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined)
3!
100
      } else {
3!
101
        yield* pattern(arg, scope, { kind, hoist, onlyBlock })
×
UNCOV
102
      }
×
103
    }
3✔
104
  } else if (arg.type === 'Identifier') {
3✔
105
    if (kind) {
3✔
106
      // If kind isn't undefined, it's a declaration
107
      scope[kind](arg.name, feed)
3✔
108
    } else {
3!
109
      // If kind is undefined, it's a statement
110
      const variable = yield* Identifier(arg, scope, { getVar: true })
×
111
      variable.set(feed)
×
UNCOV
112
    }
×
113
  } else {
3!
114
    yield* pattern(arg, scope, { kind, feed })
×
UNCOV
115
  }
×
116
}
6✔
117

118
export function* AssignmentPattern(node: acorn.AssignmentPattern, scope: Scope, options: PatternOptions = {}) {
1✔
119
  const { kind = 'var', hoist = false, onlyBlock = false, feed = yield* evaluate(node.right, scope) } = options
×
120
  const left = node.left
×
121
  if (hoist) {
×
122
    if (onlyBlock || kind === 'var') {
×
123
      if (left.type === 'Identifier') {
×
124
        scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined)
×
UNCOV
125
      } else {
×
126
        yield* pattern(left, scope, { kind, hoist, onlyBlock })
×
UNCOV
127
      }
×
UNCOV
128
    }
×
129
  } else if (left.type === 'Identifier') {
×
130
    scope[kind](left.name, feed)
×
UNCOV
131
  } else {
×
132
    yield* pattern(left, scope, { kind, feed })
×
UNCOV
133
  }
×
UNCOV
134
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc