mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-08 14:02:09 +01:00
_BrunoNewFunctionInnerContext
to __bruno__functionInnerContext
This commit is contained in:
parent
22612a7dbe
commit
434ae6c70f
@ -7,7 +7,7 @@ describe('utils', () => {
|
|||||||
res: {
|
res: {
|
||||||
data: { pets: ['bruno', 'max'] },
|
data: { pets: ['bruno', 'max'] },
|
||||||
context: 'testContext',
|
context: 'testContext',
|
||||||
_BrunoNewFunctionInnerContext: 0
|
__bruno__functionInnerContext: 0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -47,32 +47,32 @@ describe('utils', () => {
|
|||||||
it('should identify top level variables', () => {
|
it('should identify top level variables', () => {
|
||||||
const expr = 'res.data.pets[0].toUpperCase()';
|
const expr = 'res.data.pets[0].toUpperCase()';
|
||||||
evaluateJsExpression(expr, context);
|
evaluateJsExpression(expr, context);
|
||||||
expect(cache.get(expr).toString()).toContain('let { res } = _BrunoNewFunctionInnerContext;');
|
expect(cache.get(expr).toString()).toContain('let { res } = __bruno__functionInnerContext;');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not duplicate variables', () => {
|
it('should not duplicate variables', () => {
|
||||||
const expr = 'res.data.pets[0] + res.data.pets[1]';
|
const expr = 'res.data.pets[0] + res.data.pets[1]';
|
||||||
evaluateJsExpression(expr, context);
|
evaluateJsExpression(expr, context);
|
||||||
expect(cache.get(expr).toString()).toContain('let { res } = _BrunoNewFunctionInnerContext;');
|
expect(cache.get(expr).toString()).toContain('let { res } = __bruno__functionInnerContext;');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should exclude js keywords like true false from vars', () => {
|
it('should exclude js keywords like true false from vars', () => {
|
||||||
const expr = 'res.data.pets.length > 0 ? true : false';
|
const expr = 'res.data.pets.length > 0 ? true : false';
|
||||||
evaluateJsExpression(expr, context);
|
evaluateJsExpression(expr, context);
|
||||||
expect(cache.get(expr).toString()).toContain('let { res } = _BrunoNewFunctionInnerContext;');
|
expect(cache.get(expr).toString()).toContain('let { res } = __bruno__functionInnerContext;');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should exclude numbers from vars', () => {
|
it('should exclude numbers from vars', () => {
|
||||||
const expr = 'res.data.pets.length + 10';
|
const expr = 'res.data.pets.length + 10';
|
||||||
evaluateJsExpression(expr, context);
|
evaluateJsExpression(expr, context);
|
||||||
expect(cache.get(expr).toString()).toContain('let { res } = _BrunoNewFunctionInnerContext;');
|
expect(cache.get(expr).toString()).toContain('let { res } = __bruno__functionInnerContext;');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should pick variables from complex expressions', () => {
|
it('should pick variables from complex expressions', () => {
|
||||||
const expr = 'res.data.pets.map(pet => pet.length)';
|
const expr = 'res.data.pets.map(pet => pet.length)';
|
||||||
const result = evaluateJsExpression(expr, context);
|
const result = evaluateJsExpression(expr, context);
|
||||||
expect(result).toEqual([5, 3]);
|
expect(result).toEqual([5, 3]);
|
||||||
expect(cache.get(expr).toString()).toContain('let { res, pet } = _BrunoNewFunctionInnerContext;');
|
expect(cache.get(expr).toString()).toContain('let { res, pet } = __bruno__functionInnerContext;');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be ok picking extra vars from strings', () => {
|
it('should be ok picking extra vars from strings', () => {
|
||||||
@ -80,7 +80,7 @@ describe('utils', () => {
|
|||||||
const result = evaluateJsExpression(expr, context);
|
const result = evaluateJsExpression(expr, context);
|
||||||
expect(result).toBe('hello bruno');
|
expect(result).toBe('hello bruno');
|
||||||
// extra var hello is harmless
|
// extra var hello is harmless
|
||||||
expect(cache.get(expr).toString()).toContain('let { hello, res } = _BrunoNewFunctionInnerContext;');
|
expect(cache.get(expr).toString()).toContain('let { hello, res } = __bruno__functionInnerContext;');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should evaluate expressions referencing globals', () => {
|
it('should evaluate expressions referencing globals', () => {
|
||||||
@ -118,14 +118,14 @@ describe('utils', () => {
|
|||||||
it('should allow "context" as a var name', () => {
|
it('should allow "context" as a var name', () => {
|
||||||
const expr = 'res["context"].toUpperCase()';
|
const expr = 'res["context"].toUpperCase()';
|
||||||
evaluateJsExpression(expr, context);
|
evaluateJsExpression(expr, context);
|
||||||
expect(cache.get(expr).toString()).toContain('let { res, context } = _BrunoNewFunctionInnerContext;');
|
expect(cache.get(expr).toString()).toContain('let { res, context } = __bruno__functionInnerContext;');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when we use "_BrunoNewFunctionInnerContext" as a var name', () => {
|
it('should throw an error when we use "__bruno__functionInnerContext" as a var name', () => {
|
||||||
const expr = 'res["_BrunoNewFunctionInnerContext"].toUpperCase()';
|
const expr = 'res["__bruno__functionInnerContext"].toUpperCase()';
|
||||||
expect(() => evaluateJsExpression(expr, context)).toThrow(SyntaxError);
|
expect(() => evaluateJsExpression(expr, context)).toThrow(SyntaxError);
|
||||||
expect(() => evaluateJsExpression(expr, context)).toThrow(
|
expect(() => evaluateJsExpression(expr, context)).toThrow(
|
||||||
"Identifier '_BrunoNewFunctionInnerContext' has already been declared"
|
"Identifier '__bruno__functionInnerContext' has already been declared"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user