Skip to content

Commit

Permalink
$mol_sourcemap fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Oct 25, 2023
1 parent bcb7241 commit fba3cfe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
16 changes: 9 additions & 7 deletions sourcemap/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,16 @@ namespace $ {

if (segment.length >= 5) {
const nameIndex = segment[4]!
const name = raw.names[nameIndex]
let mergedNameIndex = name_indexes.get(name)
if (mergedNameIndex === undefined) {
mergedNameIndex = names.length
name_indexes.set(name, mergedNameIndex)
names.push(name)
const name = raw.names?.[nameIndex]
if (name !== undefined) {
let mergedNameIndex = name_indexes.get(name)
if (mergedNameIndex === undefined) {
mergedNameIndex = names.length
name_indexes.set(name, mergedNameIndex)
names.push(name)
}
mergedSegment.push(mergedNameIndex)
}
mergedSegment.push(mergedNameIndex)
}

mergedLine.push(mergedSegment)
Expand Down
22 changes: 14 additions & 8 deletions sourcemap/dataurl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@ namespace $ {

if (index === -1) return undefined

data = data.substring(index)
data = data.substring(index + prefix.length)

if (data.endsWith(end_comment)) data = data.substring(0, end_comment.length)
if (data.endsWith(end_comment)) data = data.substring(0, data.length - end_comment.length)

const decoded = this.decodeURIComponent(data)
const map = JSON.parse(decoded) as $mol_sourcemap_raw | null

if (! map) return undefined
try {
const map = JSON.parse(decoded) as $mol_sourcemap_raw | null

if (typeof map.mappings === 'string' && map.mappings.startsWith(';;')) {
map.mappings = map.mappings.substring(2)
}
if (! map) return undefined

if (typeof map.mappings === 'string' && map.mappings.startsWith(';;')) {
map.mappings = map.mappings.substring(2)
}

return map
return map
} catch (e) {
if (e instanceof Error) e.message += ', origin=' + decoded
$mol_fail_hidden(e)
}
}

export function $mol_sourcemap_dataurl_encode(this: $, map: $mol_sourcemap_raw, type = 'js' as 'js' | 'css') {
Expand Down
2 changes: 1 addition & 1 deletion sourcemap/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace $ {
export interface $mol_sourcemap_raw {
version: number
sources: string[]
names: string[]
names?: string[]
sourceRoot?: string
sourcesContent?: (string | null)[]
mappings: string | $mol_sourcemap_line[]
Expand Down
1 change: 0 additions & 1 deletion tree2/text/to/sourcemap/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ namespace $ {

const map: $mol_sourcemap_raw = {
version: 3,
names: [],
sources: [ ... file_sources.keys() ],
sourcesContent: [ ... file_sources.values() ],
mappings,
Expand Down

0 comments on commit fba3cfe

Please sign in to comment.