Fix some more
This commit is contained in:
@ -568,7 +568,7 @@ describe('testing pipe operator special', () => {
|
||||
type: 'Literal',
|
||||
start: 139,
|
||||
end: 141,
|
||||
value: { type: 'string', data: 45 },
|
||||
value: { type: 'i_integer', data: 45 },
|
||||
raw: '45',
|
||||
},
|
||||
{ type: 'PipeSubstitution', start: 143, end: 144 },
|
||||
@ -646,7 +646,7 @@ describe('testing pipe operator special', () => {
|
||||
type: 'Literal',
|
||||
start: 30,
|
||||
end: 32,
|
||||
value: { type: 'string', data: 45 },
|
||||
value: { type: 'i_integer', data: 45 },
|
||||
raw: '45',
|
||||
},
|
||||
{
|
||||
@ -1548,10 +1548,7 @@ const key = 'c'`
|
||||
value: {
|
||||
type: 'inlineComment',
|
||||
style: 'block',
|
||||
value: {
|
||||
type: 'string',
|
||||
data: 'this is\n a comment\n spanning a few lines',
|
||||
},
|
||||
value: 'this is\n a comment\n spanning a few lines',
|
||||
},
|
||||
})
|
||||
})
|
||||
@ -1574,7 +1571,7 @@ const key = 'c'`
|
||||
end: 138,
|
||||
value: {
|
||||
type: 'blockComment',
|
||||
value: { type: 'string', data: 'a comment' },
|
||||
value: 'a comment',
|
||||
style: 'line',
|
||||
},
|
||||
})
|
||||
@ -1608,7 +1605,7 @@ describe('test UnaryExpression', () => {
|
||||
type: 'Literal',
|
||||
start: 22,
|
||||
end: 25,
|
||||
value: { type: 'string', data: 100 },
|
||||
value: { type: 'i_integer', data: 100 },
|
||||
raw: '100',
|
||||
},
|
||||
],
|
||||
@ -1634,7 +1631,7 @@ describe('testing nested call expressions', () => {
|
||||
type: 'Literal',
|
||||
start: 18,
|
||||
end: 21,
|
||||
value: { type: 'string', data: 100 },
|
||||
value: { type: 'i_integer', data: 100 },
|
||||
raw: '100',
|
||||
},
|
||||
{
|
||||
|
||||
@ -21,7 +21,7 @@ describe('Testing createLiteral', () => {
|
||||
it('should create a literal', () => {
|
||||
const result = createLiteral(5)
|
||||
expect(result.type).toBe('Literal')
|
||||
expect(result.value).toBe(5)
|
||||
expect(result.value.data).toBe(5)
|
||||
})
|
||||
})
|
||||
describe('Testing createIdentifier', () => {
|
||||
@ -38,7 +38,7 @@ describe('Testing createCallExpression', () => {
|
||||
expect(result.callee.type).toBe('Identifier')
|
||||
expect(result.callee.name).toBe('myFunc')
|
||||
expect(result.arguments[0].type).toBe('Literal')
|
||||
expect((result.arguments[0] as any).value).toBe(5)
|
||||
expect((result.arguments[0] as any).value.data).toBe(5)
|
||||
})
|
||||
})
|
||||
describe('Testing createObjectExpression', () => {
|
||||
@ -50,7 +50,7 @@ describe('Testing createObjectExpression', () => {
|
||||
expect(result.properties[0].type).toBe('ObjectProperty')
|
||||
expect(result.properties[0].key.name).toBe('myProp')
|
||||
expect(result.properties[0].value.type).toBe('Literal')
|
||||
expect((result.properties[0].value as any).value).toBe(5)
|
||||
expect((result.properties[0].value as any).value.data).toBe(5)
|
||||
})
|
||||
})
|
||||
describe('Testing createArrayExpression', () => {
|
||||
@ -58,7 +58,7 @@ describe('Testing createArrayExpression', () => {
|
||||
const result = createArrayExpression([createLiteral(5)])
|
||||
expect(result.type).toBe('ArrayExpression')
|
||||
expect(result.elements[0].type).toBe('Literal')
|
||||
expect((result.elements[0] as any).value).toBe(5)
|
||||
expect((result.elements[0] as any).value.data).toBe(5)
|
||||
})
|
||||
})
|
||||
describe('Testing createPipeSubstitution', () => {
|
||||
@ -75,7 +75,7 @@ describe('Testing createVariableDeclaration', () => {
|
||||
expect(result.declarations[0].id.type).toBe('Identifier')
|
||||
expect(result.declarations[0].id.name).toBe('myVar')
|
||||
expect(result.declarations[0].init.type).toBe('Literal')
|
||||
expect((result.declarations[0].init as any).value).toBe(5)
|
||||
expect((result.declarations[0].init as any).value.data).toBe(5)
|
||||
})
|
||||
})
|
||||
describe('Testing createPipeExpression', () => {
|
||||
@ -83,7 +83,7 @@ describe('Testing createPipeExpression', () => {
|
||||
const result = createPipeExpression([createLiteral(5)])
|
||||
expect(result.type).toBe('PipeExpression')
|
||||
expect(result.body[0].type).toBe('Literal')
|
||||
expect((result.body[0] as any).value).toBe(5)
|
||||
expect((result.body[0] as any).value.data).toBe(5)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@ use parse_display::{Display, FromStr};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Map;
|
||||
use serde_json::Number as JNumber;
|
||||
use serde_json::Value as JValue;
|
||||
use tower_lsp::lsp_types::{CompletionItem, CompletionItemKind, DocumentSymbol, Range as LspRange, SymbolKind};
|
||||
|
||||
@ -1343,8 +1342,7 @@ impl Literal {
|
||||
|
||||
fn recast(&self) -> String {
|
||||
match self.value {
|
||||
LiteralValue::Fractional(n) => JNumber::from_f64(n).unwrap().to_string(),
|
||||
LiteralValue::IInteger(n) => JNumber::from(n).to_string(),
|
||||
LiteralValue::Fractional(_) | LiteralValue::IInteger(_) => self.raw.clone(),
|
||||
LiteralValue::String(ref s) => {
|
||||
let quote = if self.raw.trim().starts_with('"') { '"' } else { '\'' };
|
||||
format!("{quote}{s}{quote}")
|
||||
|
||||
Reference in New Issue
Block a user