зеркало из https://github.com/microsoft/gather.git
Bugfix: augassign operators update variables
This commit is contained in:
Родитель
85b193705b
Коммит
0ad10fd2c4
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "nbgather",
|
||||
"version": "0.3.3",
|
||||
"version": "0.3.4",
|
||||
"keywords": [
|
||||
"jupyter",
|
||||
"jupyterlab"
|
||||
|
|
|
@ -247,6 +247,17 @@ export class DataflowAnalyzer {
|
|||
ast.walk(target, targetsDefListener);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* If `statement.op` is defined, then it is an augassign (e.g., +=). Any variables defined
|
||||
* on the left-hand side are actually getting updated.
|
||||
*/
|
||||
if (statement.op) {
|
||||
for (let targetDef of targetsDefListener.defs.items) {
|
||||
if (targetDef.level === ReferenceType.DEFINITION) {
|
||||
targetDef.level = ReferenceType.UPDATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
defs = defs.union(targetsDefListener.defs);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -181,7 +181,12 @@ describe('getDefs', () => {
|
|||
describe('detects definitions', () => {
|
||||
it('for assignments', () => {
|
||||
let defs = getDefsFromStatement('a = 1');
|
||||
expect(defs[0]).to.include({ type: SymbolType.VARIABLE, name: 'a' });
|
||||
expect(defs[0]).to.include({ type: SymbolType.VARIABLE, name: 'a', level: ReferenceType.DEFINITION });
|
||||
});
|
||||
|
||||
it('for augmenting assignments', () => {
|
||||
let defs = getDefsFromStatement('a += 1');
|
||||
expect(defs[0]).to.include({ type: SymbolType.VARIABLE, name: 'a', level: ReferenceType.UPDATE });
|
||||
});
|
||||
|
||||
it('for imports', () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче