Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(babel-plugin-remove-graphql-queries): Convert murmur.js #22458

Merged
4 changes: 2 additions & 2 deletions packages/babel-plugin-remove-graphql-queries/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"graphql": "^14.1.1"
},
"scripts": {
"build": "babel src --out-dir . --ignore \"**/__tests__\"",
"build": "babel src --out-dir . --ignore \"**/__tests__\" --extensions \".ts,.js\"",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore \"**/__tests__\""
"watch": "babel -w src --out-dir . --ignore \"**/__tests__\" --extensions \".ts,.js\""
},
"engines": {
"node": ">=10.13.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-remove-graphql-queries/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable new-cap */
const graphql = require(`gatsby/graphql`)
const murmurhash = require(`./murmur`)
const { murmurhash } = require(`./murmur`)
const nodePath = require(`path`)

class StringInterpolationNotAllowedError extends Error {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// murmurhash2 via https://gist.github.com/raycmorgan/588423

module.exports = (str, seed) => {
let m = 0x5bd1e995
let r = 24
let h = seed ^ str.length
let length = str.length
export const murmurhash = (str: string, seed: number): number => {
const m = 0x5bd1e995
const r = 24
let h: number = seed ^ str.length
let length: number = str.length
let currentIndex = 0

while (length >= 4) {
let k = UInt32(str, currentIndex)
let k: number = UInt32(str, currentIndex)

k = Umul32(k, m)
k ^= k >>> r
Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = (str, seed) => {
return h >>> 0
}

function UInt32(str, pos) {
function UInt32(str: string, pos: number): number {
return (
str.charCodeAt(pos++) +
(str.charCodeAt(pos++) << 8) +
Expand All @@ -55,15 +55,15 @@ function UInt32(str, pos) {
)
}

function UInt16(str, pos) {
function UInt16(str: string, pos: number): number {
return str.charCodeAt(pos++) + (str.charCodeAt(pos++) << 8)
}

function Umul32(n, m) {
function Umul32(n: number, m: number): number {
n = n | 0
m = m | 0
let nlo = n & 0xffff
let nhi = n >>> 16
let res = (nlo * m + (((nhi * m) & 0xffff) << 16)) | 0
const nlo = n & 0xffff
const nhi = n >>> 16
const res = (nlo * m + (((nhi * m) & 0xffff) << 16)) | 0
return res
}