Skip to content

Commit 817fb9c

Browse files
committed
AE_ Use rewriting to get setMember locations
SQUASHED: AUTO-COMMIT-src-client-reactive-active-expression-rewriting-active-expression-rewriting.js,AUTO-COMMIT-src-client-reactive-babel-plugin-active-expression-rewriting-index.js,AUTO-COMMIT-src-client-reactive-components-rewritten-aexpr-test-component.js,AUTO-COMMIT-src-client-reactive-components-rewritten-poll.js,AUTO-COMMIT-src-components-widgets-lively-code-mirror.js,
1 parent b2b1df9 commit 817fb9c

File tree

5 files changed

+94
-94
lines changed

5 files changed

+94
-94
lines changed

src/client/reactive/active-expression-rewriting/active-expression-rewriting.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,6 @@ class Hook {
356356

357357
addLocation(location) {
358358
this.locations.push(location);
359-
const self = this;
360-
location.then((l) => {
361-
console.log(self.constructor.name)
362-
console.log(l)
363-
});
364359
}
365360

366361
async getLocations() {
@@ -726,24 +721,24 @@ class TracingHandler {
726721
* ********************** update ********************************
727722
* **************************************************************
728723
*/
729-
static memberUpdated(obj, prop) {
724+
static memberUpdated(obj, prop, location) {
730725
const hook = SourceCodeHook.get(obj, prop);
731726
if(!hook) return;
732-
hook.addLocation(TracingHandler.findRegistrationLocation());
727+
hook.addLocation(location || TracingHandler.findRegistrationLocation());
733728
hook.notifyDependencies();
734729
}
735730

736-
static globalUpdated(globalName) {
731+
static globalUpdated(globalName, location) {
737732
const hook = SourceCodeHook.get(globalRef, globalName);
738733
if(!hook) return;
739-
hook.addLocation(TracingHandler.findRegistrationLocation());
734+
hook.addLocation(location || TracingHandler.findRegistrationLocation());
740735
hook.notifyDependencies();
741736
}
742737

743-
static localUpdated(scope, varName) {
738+
static localUpdated(scope, varName, location) {
744739
const hook = SourceCodeHook.get(scope, varName);
745740
if(!hook) return;
746-
hook.addLocation(TracingHandler.findRegistrationLocation());
741+
hook.addLocation(location || TracingHandler.findRegistrationLocation());
747742
hook.notifyDependencies();
748743
}
749744

@@ -754,7 +749,12 @@ class TracingHandler {
754749

755750
for (let frame of frames.slice()) {
756751
if (!frame.file.includes("active-expression")) {
757-
return frame.getSourceLoc();
752+
const loc = await frame.getSourceLoc();
753+
return {
754+
start: {line: loc.line, column: loc.column},
755+
end: {line: loc.line, column: loc.column},
756+
file: loc.source,
757+
}
758758
}
759759
}
760760
return undefined;
@@ -805,87 +805,87 @@ export function getAndCallMember(obj, prop, args = []) {
805805
return result;
806806
}
807807

808-
export function setMember(obj, prop, val) {
808+
export function setMember(obj, prop, val, location) {
809809
const result = obj[prop] = val;
810-
TracingHandler.memberUpdated(obj, prop);
810+
TracingHandler.memberUpdated(obj, prop, location);
811811
return result;
812812
}
813813

814-
export function setMemberAddition(obj, prop, val) {
814+
export function setMemberAddition(obj, prop, val, location) {
815815
const result = obj[prop] += val;
816-
TracingHandler.memberUpdated(obj, prop);
816+
TracingHandler.memberUpdated(obj, prop, location);
817817
return result;
818818
}
819819

820-
export function setMemberSubtraction(obj, prop, val) {
820+
export function setMemberSubtraction(obj, prop, val, location) {
821821
const result = obj[prop] -= val;
822-
TracingHandler.memberUpdated(obj, prop);
822+
TracingHandler.memberUpdated(obj, prop, location);
823823
return result;
824824
}
825825

826-
export function setMemberMultiplication(obj, prop, val) {
826+
export function setMemberMultiplication(obj, prop, val, location) {
827827
const result = obj[prop] *= val;
828-
TracingHandler.memberUpdated(obj, prop);
828+
TracingHandler.memberUpdated(obj, prop, location);
829829
return result;
830830
}
831831

832-
export function setMemberDivision(obj, prop, val) {
832+
export function setMemberDivision(obj, prop, val, location) {
833833
const result = obj[prop] /= val;
834-
TracingHandler.memberUpdated(obj, prop);
834+
TracingHandler.memberUpdated(obj, prop, location);
835835
return result;
836836
}
837837

838-
export function setMemberRemainder(obj, prop, val) {
838+
export function setMemberRemainder(obj, prop, val, location) {
839839
const result = obj[prop] %= val;
840-
TracingHandler.memberUpdated(obj, prop);
840+
TracingHandler.memberUpdated(obj, prop, location);
841841
return result;
842842
}
843843

844-
export function setMemberExponentiation(obj, prop, val) {
844+
export function setMemberExponentiation(obj, prop, val, location) {
845845
const result = obj[prop] **= val;
846-
TracingHandler.memberUpdated(obj, prop);
846+
TracingHandler.memberUpdated(obj, prop, location);
847847
return result;
848848
}
849849

850-
export function setMemberLeftShift(obj, prop, val) {
850+
export function setMemberLeftShift(obj, prop, val, location) {
851851
const result = obj[prop] <<= val;
852-
TracingHandler.memberUpdated(obj, prop);
852+
TracingHandler.memberUpdated(obj, prop, location);
853853
return result;
854854
}
855855

856-
export function setMemberRightShift(obj, prop, val) {
856+
export function setMemberRightShift(obj, prop, val, location) {
857857
const result = obj[prop] >>= val;
858-
TracingHandler.memberUpdated(obj, prop);
858+
TracingHandler.memberUpdated(obj, prop, location);
859859
return result;
860860
}
861861

862-
export function setMemberUnsignedRightShift(obj, prop, val) {
862+
export function setMemberUnsignedRightShift(obj, prop, val, location) {
863863
const result = obj[prop] >>>= val;
864-
TracingHandler.memberUpdated(obj, prop);
864+
TracingHandler.memberUpdated(obj, prop, location);
865865
return result;
866866
}
867867

868-
export function setMemberBitwiseAND(obj, prop, val) {
868+
export function setMemberBitwiseAND(obj, prop, val, location) {
869869
const result = obj[prop] &= val;
870-
TracingHandler.memberUpdated(obj, prop);
870+
TracingHandler.memberUpdated(obj, prop, location);
871871
return result;
872872
}
873873

874-
export function setMemberBitwiseXOR(obj, prop, val) {
874+
export function setMemberBitwiseXOR(obj, prop, val, location) {
875875
const result = obj[prop] ^= val;
876-
TracingHandler.memberUpdated(obj, prop);
876+
TracingHandler.memberUpdated(obj, prop, location);
877877
return result;
878878
}
879879

880-
export function setMemberBitwiseOR(obj, prop, val) {
880+
export function setMemberBitwiseOR(obj, prop, val, location) {
881881
const result = obj[prop] |= val;
882-
TracingHandler.memberUpdated(obj, prop);
882+
TracingHandler.memberUpdated(obj, prop, location);
883883
return result;
884884
}
885885

886-
export function deleteMember(obj, prop) {
886+
export function deleteMember(obj, prop, location) {
887887
const result = delete obj[prop];
888-
TracingHandler.memberUpdated(obj, prop);
888+
TracingHandler.memberUpdated(obj, prop, location);
889889
return result;
890890
}
891891

@@ -896,9 +896,9 @@ export function getLocal(scope, varName, value) {
896896
}
897897
}
898898

899-
export function setLocal(scope, varName, value) {
899+
export function setLocal(scope, varName, value, location) {
900900
scope[varName] = value;
901-
TracingHandler.localUpdated(scope, varName);
901+
TracingHandler.localUpdated(scope, varName, location);
902902
}
903903

904904
export function getGlobal(globalName) {
@@ -914,7 +914,7 @@ export async function getDependencyTriplesForFile(url) {
914914
for (const dependency of HooksToDependencies.getDepsForHook(hook)) {
915915
for (const ae of DependenciesToAExprs.getAExprsForDep(dependency)) {
916916
const location = ae.meta().get("location").file;
917-
if (location.includes(url) || locations.some(loc => loc && loc.source.includes(url))) {
917+
if (location.includes(url) || locations.some(loc => loc && loc.file.includes(url))) {
918918
result.push({ hook, dependency, ae });
919919
}
920920
}
@@ -931,8 +931,8 @@ export async function getAETriplesForFile(url) {
931931
return DependenciesToAExprs.getAETriplesForFile(url);
932932
}
933933

934-
export function setGlobal(globalName) {
935-
TracingHandler.globalUpdated(globalName);
934+
export function setGlobal(globalName, location) {
935+
TracingHandler.globalUpdated(globalName, location);
936936
}
937937

938938
export default aexpr;

src/client/reactive/babel-plugin-active-expression-rewriting/index.js

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export default function(babel) {
276276
t.sequenceExpression([
277277
path.node,
278278
t.callExpression(
279-
addCustomTemplate(state.file, SET_GLOBAL), [t.stringLiteral(path.node.left.name)]
279+
addCustomTemplate(state.file, SET_GLOBAL), [t.stringLiteral(path.node.left.name), getSourceLocation(path)]
280280
),
281281
valueToReturn
282282
]));
@@ -301,6 +301,39 @@ export default function(babel) {
301301
return false;
302302
}
303303

304+
function getSourceLocation(path) {
305+
let fileName = state && state.file && state.file.log && state.file.log.filename || 'no_file_given';
306+
if(fileName.startsWith('workspace:') && fileName.includes('unnamed_module_')) {
307+
fileName = 'workspace:'+fileName.split('unnamed_module_')[1];
308+
}
309+
const node = path.node;
310+
if(!node.loc) {
311+
console.error("Make sure to add loc information manually when inserting an AE or assignment while transforming")
312+
return t.identifier("undefined");
313+
}
314+
315+
const sourceLocation = template(`({
316+
file: '${fileName}',
317+
end: {
318+
column: END_COLUMN,
319+
line: END_LINE
320+
},
321+
start: {
322+
column: START_COLUMN,
323+
line: START_LINE
324+
},
325+
source: ''
326+
})`);
327+
328+
// let source = babel.transformFromAst(wrapper, {sourceType: 'module'}).code;
329+
return sourceLocation({
330+
END_COLUMN: t.numericLiteral(node.loc.end.column),
331+
END_LINE: t.numericLiteral(node.loc.end.line),
332+
START_COLUMN: t.numericLiteral(node.loc.start.column),
333+
START_LINE: t.numericLiteral(node.loc.start.line),
334+
// SOURCE: source
335+
}).expression;
336+
}
304337

305338
// ------------- ensureBlock -------------
306339
const maybeWrapInStatement = (node, wrapInReturnStatement) => {
@@ -399,6 +432,7 @@ export default function(babel) {
399432
argument.node,
400433
t.numericLiteral(1),
401434
)
435+
assignment.loc = path.node.loc;
402436

403437
if(!prefix) {
404438
// need to modify result for postfix operators
@@ -409,8 +443,8 @@ export default function(babel) {
409443
assignment,
410444
t.numericLiteral(1)
411445
)
446+
assignment.loc = path.node.loc;
412447
}
413-
414448
path.replaceWith(assignment);
415449
}
416450
},
@@ -485,43 +519,6 @@ export default function(babel) {
485519
}
486520
}
487521

488-
function addSourceLocationToSecondParameter(aexprIdentifierPath) {
489-
let fileName = state && state.file && state.file.log && state.file.log.filename || 'no_file_given';
490-
if(fileName.startsWith('workspace:') && fileName.includes('unnamed_module_')) {
491-
fileName = 'workspace:'+fileName.split('unnamed_module_')[1];
492-
}
493-
494-
const sourceLocation = template(`({
495-
file: '${fileName}',
496-
end: {
497-
column: END_COLUMN,
498-
line: END_LINE
499-
},
500-
start: {
501-
column: START_COLUMN,
502-
line: START_LINE
503-
},
504-
source: ''
505-
})`);
506-
function buildSourceLocation(aexprIdentifierPath) {
507-
const node = aexprIdentifierPath.node;
508-
if(!node.loc) {
509-
console.error("Make sure to add loc information manually when inserting an AE during transformation")
510-
}
511-
// let source = babel.transformFromAst(wrapper, {sourceType: 'module'}).code;
512-
return sourceLocation({
513-
END_COLUMN: t.numericLiteral(node.loc.end.column),
514-
END_LINE: t.numericLiteral(node.loc.end.line),
515-
START_COLUMN: t.numericLiteral(node.loc.start.column),
516-
START_LINE: t.numericLiteral(node.loc.start.line),
517-
// SOURCE: source
518-
}).expression;
519-
}
520-
521-
const location = buildSourceLocation(aexprIdentifierPath);
522-
addAsObjectPropertyAsSecondParameter(aexprIdentifierPath.parentPath, 'location', location);
523-
}
524-
525522
function addOriginalSourceCode(aexprIdentifierPath) {
526523
const args = aexprIdentifierPath.parentPath.get('arguments');
527524
if (args.length === 0) {
@@ -535,7 +532,8 @@ export default function(babel) {
535532
}
536533

537534
function addSourceMetaData(path) {
538-
addSourceLocationToSecondParameter(path);
535+
const location = getSourceLocation(path);
536+
addAsObjectPropertyAsSecondParameter(path.parentPath, 'location', location);
539537
addOriginalSourceCode(path);
540538
}
541539

@@ -743,7 +741,8 @@ export default function(babel) {
743741
path.node.left.object,
744742
getPropertyFromMemberExpression(path.node.left),
745743
//t.stringLiteral(path.node.operator),
746-
path.node.right
744+
path.node.right,
745+
getSourceLocation(path),
747746
]
748747
)
749748
);
@@ -788,7 +787,8 @@ export default function(babel) {
788787
addCustomTemplate(state.file, SET_LOCAL), [
789788
getIdentifierForExplicitScopeObject(parentWithScope),
790789
t.stringLiteral(path.node.left.name),
791-
valueForAExpr
790+
valueForAExpr,
791+
getSourceLocation(path),
792792
]
793793
),
794794
t.unaryExpression('void', t.numericLiteral(0))

src/client/reactive/components/rewritten/aexpr-test-component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Poll from 'src/client/reactive/components/rewritten/poll.js';
77
export default class AexprTest extends Morph {
88

99
async initialize() {
10+
this.c = 0;
1011
this.windowTitle = "Active Expression Testing";
1112
this.aes = [];
1213
this.y = 4;
@@ -16,7 +17,6 @@ export default class AexprTest extends Morph {
1617
this.deleteButton.addEventListener('click', () => this.deleteAEs());
1718
}
1819

19-
2020
addAE() {
2121
let z = 4;
2222
this.aes.push(aexpr(() => this.x.getBestOption() + this.y + z));

src/client/reactive/components/rewritten/poll.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default class Poll {
99

1010
addVoteToOption(index) {
1111
this.options[index] = this.options[index] + 1;
12-
this.options.values();
12+
this.options.values();
1313
}
1414

1515
getBestOption() {

0 commit comments

Comments
 (0)