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

source-academy / js-slang / 5406352152

pending completion
5406352152

Pull #1428

github

web-flow
Merge 0380f5ed7 into 8618e26e4
Pull Request #1428: Further Enhancements to the Module System

3611 of 4728 branches covered (76.37%)

Branch coverage included in aggregate %.

831 of 831 new or added lines in 50 files covered. (100.0%)

10852 of 12603 relevant lines covered (86.11%)

93898.15 hits per line

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

85.45
/src/utils/ast/astUtils.ts
1
import assert from '../assert'
58✔
2
import { isDeclaration } from './typeGuards'
58✔
3
import type * as es from './types'
4
import { recursive } from './walkers'
58✔
5

6
export function extractIdsFromPattern(pattern: es.Pattern): Set<es.Identifier> {
58✔
7
  const ids = new Set<es.Identifier>()
30,037✔
8
  if (pattern.type === 'MemberExpression') return ids
30,037!
9

10
  recursive(pattern, null, {
30,037✔
11
    ArrayPattern: ({ elements }: es.ArrayPattern, _state, c) =>
12
      elements.forEach(elem => {
10✔
13
        if (elem) c(elem, null)
21✔
14
      }),
15
    AssignmentPattern: (p: es.AssignmentPattern, _state, c) => {
16
      c(p.left, null)
×
17
      c(p.right, null)
×
18
    },
19
    Identifier: (id: es.Identifier) => ids.add(id),
30,057✔
20
    ObjectPattern: ({ properties }: es.ObjectPattern, _state, c) =>
21
      properties.forEach(prop => c(prop, null)),
25✔
22
    RestElement: ({ argument }: es.RestElement, _state, c) => c(argument, null)
9✔
23
  })
24
  return ids
30,037✔
25
}
26

27
export function declarationToExpression(node: es.ClassDeclaration): es.ClassExpression
28
export function declarationToExpression(node: es.FunctionDeclaration): es.FunctionExpression
29
export function declarationToExpression({
58✔
30
  type,
×
31
  ...node
×
32
}: es.FunctionDeclaration | es.ClassDeclaration) {
33
  return {
×
34
    ...node,
35
    type: type === 'FunctionDeclaration' ? 'FunctionExpression' : 'ClassExpression'
×
36
  } as es.FunctionExpression | es.ClassExpression
37
}
38

39
type ExportDefaultProcessors<T> = {
40
  FunctionDeclaration: (node: es.FunctionDeclarationWithId) => T
41
  ClassDeclaration: (node: es.ClassDeclarationWithId) => T
42
  Expression: (node: es.Expression) => T
43
}
44

45
export function processExportDefaultDeclaration<T>(
58✔
46
  node: es.ExportDefaultDeclaration,
47
  processors: ExportDefaultProcessors<T>
48
) {
49
  if (isDeclaration(node.declaration)) {
18✔
50
    const declaration = node.declaration
8✔
51
    assert(
8✔
52
      declaration.type !== 'VariableDeclaration',
53
      'ExportDefaultDeclarations cannot have VariableDeclarations'
54
    )
55

56
    if (declaration.type === 'FunctionDeclaration') {
8✔
57
      if (declaration.id) {
6✔
58
        return processors.FunctionDeclaration(declaration as es.FunctionDeclarationWithId)
5✔
59
      }
60

61
      return processors.Expression({
1✔
62
        ...declaration,
63
        type: 'FunctionExpression'
64
      })
65
    }
66

67
    if (declaration.id) {
2✔
68
      return processors.ClassDeclaration(declaration as es.ClassDeclarationWithId)
1✔
69
    }
70

71
    return processors.Expression({
1✔
72
      ...declaration,
73
      type: 'ClassExpression'
74
    })
75
  }
76

77
  return processors.Expression(node.declaration)
10✔
78
}
79

80
type ExportNamedProcessors<T> = {
81
  withVarDecl: (node: es.VariableDeclaration) => T
82
  withClass: (node: es.ClassDeclarationWithId) => T
83
  withFunction: (node: es.FunctionDeclarationWithId) => T
84
  localExports: (node: es.ExportNamedLocalDeclaration) => T
85
  withSource: (node: es.ExportNamedDeclarationWithSource) => T
86
}
87

88
export function processExportNamedDeclaration<T>(
58✔
89
  node: es.ExportNamedDeclaration,
90
  processors: ExportNamedProcessors<T>
91
) {
92
  if (node.declaration) {
92✔
93
    switch (node.declaration.type) {
78✔
94
      case 'VariableDeclaration':
78✔
95
        return processors.withVarDecl(node.declaration)
50✔
96
      case 'FunctionDeclaration':
97
        return processors.withFunction(node.declaration as es.FunctionDeclarationWithId)
27✔
98
      case 'ClassDeclaration':
99
        return processors.withClass(node.declaration as es.ClassDeclarationWithId)
1✔
100
    }
101
  } else if (node.source) {
14✔
102
    return processors.withSource(node as es.ExportNamedDeclarationWithSource)
9✔
103
  } else {
104
    return processors.localExports(node as es.ExportNamedLocalDeclaration)
5✔
105
  }
106
}
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

© 2026 Coveralls, Inc