Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
fix: parse minified boolean (#1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt authored Nov 22, 2023
1 parent 145bc5f commit 8ac5b33
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/runtimes/node/parser/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ const parsePrimitive = (exp: Expression | PatternLike): PrimitiveResult => {
if (exp.type === 'NullLiteral') {
return null
}

// special case: minifiers like to transform `true` to `!0` and `false` to `!1`.
// because this can be hard to turn off for some frameworks, we have a special case.
if (exp.type === 'UnaryExpression' && exp.operator === '!' && exp.argument.type === 'NumericLiteral') {
return !exp.argument.value
}
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/runtimes/node/in_source_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,5 +692,20 @@ describe('V2 API', () => {

expect(routes).toEqual([{ pattern: '/products', literal: '/products', methods: [] }])
})

test('Understands minfied true', () => {
const source = `export default async () => {
return new Response("Hello!")
}
export const config = {
path: "/products",
preferStatic: !0
}`

const { routes } = parseSource(source, options)

expect(routes).toEqual([{ pattern: '/products', literal: '/products', methods: [], prefer_static: true }])
})
})
})

1 comment on commit 8ac5b33

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

  • largeDepsEsbuild: 1.5s
  • largeDepsNft: 5.6s
  • largeDepsZisi: 10.5s

Please sign in to comment.