tokenizeLine tokenizes each line and serializes it to the provided JSDocument
(ctx context.Context, pageDir string, line string)
| 116 | |
| 117 | // tokenizeLine tokenizes each line and serializes it to the provided JSDocument |
| 118 | func (p *DefaultJSDocument) tokenizeLine(ctx context.Context, pageDir string, line string) (context.Context, error) { |
| 119 | if len(line) == 0 { |
| 120 | return ctx, nil |
| 121 | } |
| 122 | |
| 123 | parsedLine := line |
| 124 | for _, t := range stringTokens { |
| 125 | out, v := removeCenterOfToken(parsedLine, string(t)) |
| 126 | if t == MultiStringToken && v%2 == 1 { |
| 127 | p.inDeadBlock = !p.inDeadBlock |
| 128 | } |
| 129 | |
| 130 | parsedLine = out |
| 131 | } |
| 132 | |
| 133 | if p.inDeadBlock { |
| 134 | p.AddOther(line) |
| 135 | |
| 136 | return ctx, nil |
| 137 | } |
| 138 | |
| 139 | if strings.Contains(parsedLine, string(CommentToken)) { |
| 140 | // the only part of the comment line that is valid would be everything before the comment |
| 141 | commentDelimited := strings.Split(line, string(CommentToken)) |
| 142 | return p.tokenizeLine(ctx, pageDir, commentDelimited[0]) |
| 143 | } |
| 144 | |
| 145 | for _, decToken := range declarationTokens { |
| 146 | if strings.Contains(parsedLine, string(decToken)) { |
| 147 | switch decToken { |
| 148 | case ImportToken: |
| 149 | p.imports = append(p.imports, p.formatImportLine(line)) |
| 150 | return ctx, nil |
| 151 | case ExportDefaultToken, ExportConstToken: |
| 152 | name, err := extractJSTokenName(line, decToken) |
| 153 | |
| 154 | if err != nil { |
| 155 | return ctx, err |
| 156 | } |
| 157 | |
| 158 | if p.scope[name] != nil { |
| 159 | if decToken == ExportDefaultToken { |
| 160 | p.defaultExport = p.scope[name] |
| 161 | p.name = name |
| 162 | } |
| 163 | return ctx, nil |
| 164 | } else { |
| 165 | v, err := p.parseInformalExportDefault(pageDir, line) |
| 166 | if err != nil || v { |
| 167 | return ctx, err |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | name, err := extractJSTokenName(line, decToken) |
| 173 | if err != nil { |
| 174 | return ctx, err |
| 175 | } |