-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(common): Fix handling of input source maps #6561
Changes from 15 commits
71d3cfc
1efa944
81537e8
c729d9c
6ecbec9
ff145a0
767c047
4d1873d
ea276d9
2ad8cc1
7ff08d4
c638250
d724867
2b636f2
f65e03b
87115e7
ad868d0
d02f8a7
811d3a3
e0ab2ad
5d5cdff
8ecee8d
9939ca0
96f07c5
ddaabee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"env": { | ||
"targets": { | ||
"chrome": "95" | ||
} | ||
}, | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": true | ||
} | ||
}, | ||
"sourceMaps": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type { UIStore, UIThunkAction } from "ui/actions"; | ||
import { isInspectorSelected } from "ui/reducers/app"; | ||
import { AppStartListening } from "ui/setup/listenerMiddleware"; | ||
import { getBoundingRectAsync, getComputedStyleAsync } from "ui/suspense/styleCaches"; | ||
|
||
import { nodeSelected } from "../../markup/reducers/markup"; | ||
import { LAYOUT_NUMERIC_FIELDS, Layout, layoutUpdated } from "../reducers/box-model"; | ||
|
||
export function setupBoxModel(store: UIStore, startAppListening: AppStartListening) { | ||
// Any time a new node is selected in the "Markup" panel, | ||
// try to update the box model layout data | ||
startAppListening({ | ||
actionCreator: nodeSelected, | ||
effect: async (action, listenerApi) => { | ||
const { extra, getState, dispatch } = listenerApi; | ||
const { ThreadFront, protocolClient, replayClient } = extra; | ||
const state = getState(); | ||
const { selectedNode, tree } = state.markup; | ||
|
||
if (!isInspectorSelected(state) || !selectedNode || !ThreadFront.currentPause?.pauseId) { | ||
return; | ||
} | ||
|
||
const nodeInfo = tree.entities[selectedNode]; | ||
|
||
if (!nodeInfo) { | ||
return; | ||
} | ||
|
||
const [bounds, style] = await Promise.all([ | ||
getBoundingRectAsync( | ||
protocolClient, | ||
ThreadFront.sessionId!, | ||
ThreadFront.currentPause.pauseId, | ||
selectedNode | ||
), | ||
getComputedStyleAsync( | ||
protocolClient, | ||
ThreadFront.sessionId!, | ||
ThreadFront.currentPause.pauseId, | ||
selectedNode | ||
), | ||
]); | ||
|
||
if (!bounds || !style) { | ||
return; | ||
} | ||
|
||
const layout = { | ||
width: parseFloat(bounds.width.toPrecision(6)), | ||
height: parseFloat(bounds.height.toPrecision(6)), | ||
autoMargins: {}, | ||
} as Layout; | ||
|
||
for (const prop of LAYOUT_NUMERIC_FIELDS) { | ||
layout[prop] = style.get(prop)!; | ||
} | ||
|
||
// Update the redux store with the latest layout properties and update the box model view. | ||
dispatch(layoutUpdated(layout)); | ||
}, | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"mappings": "AACA,SAASA,mBAAmB,QAAQ,kBAAkB;AAEtD,SAASC,oBAAoB,EAAEC,qBAAqB,QAAQ,0BAA0B;AAEtF,SAASC,YAAY,QAAQ,+BAA+B;AAC5D,SAASC,qBAAqB,EAAUC,aAAa,QAAQ,wBAAwB;AAErF,OAAO,SAASC,cAAcC,KAAc,EAAEC,iBAAoC,EAAE;IAClF,yDAAyD;IACzD,0CAA0C;IAC1CA,kBAAkB;QAChBC,eAAeN;QACfO,QAAQ,OAAOC,QAAQC,cAAgB;YACrC,MAAM,EAAEC,MAAK,EAAEC,SAAQ,EAAEC,SAAQ,EAAE,GAAGH;YACtC,MAAM,EAAEI,YAAW,EAAEC,eAAc,EAAEC,aAAY,EAAE,GAAGL;YACtD,MAAMM,QAAQL;YACd,MAAM,EAAEM,aAAY,EAAEC,KAAI,EAAE,GAAGF,MAAMG,MAAM;YAE3C,IAAI,CAACtB,oBAAoBmB,UAAU,CAACC,gBAAgB,CAACJ,YAAYO,YAAY,EAAEC,SAAS;gBACtF;YACF,CAAC;YAED,MAAMC,WAAWJ,KAAKK,QAAQ,CAACN,aAAa;YAE5C,IAAI,CAACK,UAAU;gBACb;YACF,CAAC;YAED,MAAM,CAACE,QAAQC,MAAM,GAAG,MAAMC,QAAQC,GAAG,CAAC;gBACxC7B,qBACEgB,gBACAD,YAAYe,SAAS,EACrBf,YAAYO,YAAY,CAACC,OAAO,EAChCJ;gBAEFlB,sBACEe,gBACAD,YAAYe,SAAS,EACrBf,YAAYO,YAAY,CAACC,OAAO,EAChCJ;aAEH;YAED,IAAI,CAACO,UAAU,CAACC,OAAO;gBACrB;YACF,CAAC;YAED,MAAMI,SAAS;gBACbC,OAAOC,WAAWP,OAAOM,KAAK,CAACE,WAAW,CAAC;gBAC3CC,QAAQF,WAAWP,OAAOS,MAAM,CAACD,WAAW,CAAC;gBAC7CE,aAAa,CAAC;YAChB;YAEA,KAAK,MAAMC,QAAQlC,sBAAuB;gBACxC4B,MAAM,CAACM,KAAK,GAAGV,MAAMW,GAAG,CAACD;YAC3B;YAEA,0FAA0F;YAC1FvB,SAASV,cAAc2B;QACzB;IACF;AACF,CAAC", | ||
"names": [ | ||
"isInspectorSelected", | ||
"getBoundingRectAsync", | ||
"getComputedStyleAsync", | ||
"nodeSelected", | ||
"LAYOUT_NUMERIC_FIELDS", | ||
"layoutUpdated", | ||
"setupBoxModel", | ||
"store", | ||
"startAppListening", | ||
"actionCreator", | ||
"effect", | ||
"action", | ||
"listenerApi", | ||
"extra", | ||
"getState", | ||
"dispatch", | ||
"ThreadFront", | ||
"protocolClient", | ||
"replayClient", | ||
"state", | ||
"selectedNode", | ||
"tree", | ||
"markup", | ||
"currentPause", | ||
"pauseId", | ||
"nodeInfo", | ||
"entities", | ||
"bounds", | ||
"style", | ||
"Promise", | ||
"all", | ||
"sessionId", | ||
"layout", | ||
"width", | ||
"parseFloat", | ||
"toPrecision", | ||
"height", | ||
"autoMargins", | ||
"prop", | ||
"get" | ||
], | ||
"sources": [ | ||
"../../input/box-model.ts" | ||
], | ||
"sourcesContent": [ | ||
"import type { UIStore, UIThunkAction } from \"ui/actions\";\nimport { isInspectorSelected } from \"ui/reducers/app\";\nimport { AppStartListening } from \"ui/setup/listenerMiddleware\";\nimport { getBoundingRectAsync, getComputedStyleAsync } from \"ui/suspense/styleCaches\";\n\nimport { nodeSelected } from \"../../markup/reducers/markup\";\nimport { LAYOUT_NUMERIC_FIELDS, Layout, layoutUpdated } from \"../reducers/box-model\";\n\nexport function setupBoxModel(store: UIStore, startAppListening: AppStartListening) {\n // Any time a new node is selected in the \"Markup\" panel,\n // try to update the box model layout data\n startAppListening({\n actionCreator: nodeSelected,\n effect: async (action, listenerApi) => {\n const { extra, getState, dispatch } = listenerApi;\n const { ThreadFront, protocolClient, replayClient } = extra;\n const state = getState();\n const { selectedNode, tree } = state.markup;\n\n if (!isInspectorSelected(state) || !selectedNode || !ThreadFront.currentPause?.pauseId) {\n return;\n }\n\n const nodeInfo = tree.entities[selectedNode];\n\n if (!nodeInfo) {\n return;\n }\n\n const [bounds, style] = await Promise.all([\n getBoundingRectAsync(\n protocolClient,\n ThreadFront.sessionId!,\n ThreadFront.currentPause.pauseId,\n selectedNode\n ),\n getComputedStyleAsync(\n protocolClient,\n ThreadFront.sessionId!,\n ThreadFront.currentPause.pauseId,\n selectedNode\n ),\n ]);\n\n if (!bounds || !style) {\n return;\n }\n\n const layout = {\n width: parseFloat(bounds.width.toPrecision(6)),\n height: parseFloat(bounds.height.toPrecision(6)),\n autoMargins: {},\n } as Layout;\n\n for (const prop of LAYOUT_NUMERIC_FIELDS) {\n layout[prop] = style.get(prop)!;\n }\n\n // Update the redux store with the latest layout properties and update the box model view.\n dispatch(layoutUpdated(layout));\n },\n });\n}\n" | ||
], | ||
"version": 3 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { isInspectorSelected } from "ui/reducers/app"; | ||
import { getBoundingRectAsync, getComputedStyleAsync } from "ui/suspense/styleCaches"; | ||
import { nodeSelected } from "../../markup/reducers/markup"; | ||
import { LAYOUT_NUMERIC_FIELDS, layoutUpdated } from "../reducers/box-model"; | ||
export function setupBoxModel(store, startAppListening) { | ||
// Any time a new node is selected in the "Markup" panel, | ||
// try to update the box model layout data | ||
startAppListening({ | ||
actionCreator: nodeSelected, | ||
effect: async (action, listenerApi)=>{ | ||
const { extra , getState , dispatch } = listenerApi; | ||
const { ThreadFront , protocolClient , replayClient } = extra; | ||
const state = getState(); | ||
const { selectedNode , tree } = state.markup; | ||
if (!isInspectorSelected(state) || !selectedNode || !ThreadFront.currentPause?.pauseId) { | ||
return; | ||
} | ||
const nodeInfo = tree.entities[selectedNode]; | ||
if (!nodeInfo) { | ||
return; | ||
} | ||
const [bounds, style] = await Promise.all([ | ||
getBoundingRectAsync(protocolClient, ThreadFront.sessionId, ThreadFront.currentPause.pauseId, selectedNode), | ||
getComputedStyleAsync(protocolClient, ThreadFront.sessionId, ThreadFront.currentPause.pauseId, selectedNode) | ||
]); | ||
if (!bounds || !style) { | ||
return; | ||
} | ||
const layout = { | ||
width: parseFloat(bounds.width.toPrecision(6)), | ||
height: parseFloat(bounds.height.toPrecision(6)), | ||
autoMargins: {} | ||
}; | ||
for (const prop of LAYOUT_NUMERIC_FIELDS){ | ||
layout[prop] = style.get(prop); | ||
} | ||
// Update the redux store with the latest layout properties and update the box model view. | ||
dispatch(layoutUpdated(layout)); | ||
} | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1281,12 +1281,17 @@ impl SourceMap { | |
let mut col = max(chpos, linechpos) - min(chpos, linechpos); | ||
|
||
if let Some(orig) = &orig { | ||
if let Some(token) = orig.lookup_token(line, col) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's actually (what I consider to be) a bug in
I tried to get them to fix it in getsentry/rust-sourcemap#53, but they rejected it. This breaks with Mozilla's source map behavior, because lines endings are supposed to split the mapping from any previous one. Anyways, the "fix" is to do: orig.lookup_token(line, col).filter(|t| t.get_dst_line() == line) Is this the bug you're trying to fix with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, exactly. Thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about the reason, but it didn't work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh, we probably have an off-by-one. The visualized link you posted is definitely doing the lookup on the wrong line. The sourcemap crate uses 0-based lines, based on the readme example. |
||
if let Some(token) = orig | ||
.tokens() | ||
.find(|token| token.get_src_line() == line - 1 && token.get_src_col() == col) | ||
kdy1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
line = token.get_src_line() + 1; | ||
col = token.get_src_col(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I notice we're not pulling the |
||
if let Some(src) = token.get_source() { | ||
src_id = builder.add_source(src); | ||
} | ||
} else { | ||
continue; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This worries me, but it seems to be the input sourcemap is really bad: