diff --git a/packages/webpack-loader-runtime/src/index.ts b/packages/webpack-loader-runtime/src/index.ts index 064d561568f..ddb30fa2887 100644 --- a/packages/webpack-loader-runtime/src/index.ts +++ b/packages/webpack-loader-runtime/src/index.ts @@ -1,11 +1,11 @@ import { DefinitionNode } from 'graphql'; export const uniqueCode = ` - const names = {}; + var names = {}; function unique(defs) { - return defs.filter((def) => { + return defs.filter(function (def) { if (def.kind !== 'FragmentDefinition') return true; - const name = def.name.value; + var name = def.name.value; if (names[name]) { return false; } else { diff --git a/packages/webpack-loader/src/index.ts b/packages/webpack-loader/src/index.ts index 22fbc39d475..c5c95bc2483 100644 --- a/packages/webpack-loader/src/index.ts +++ b/packages/webpack-loader/src/index.ts @@ -43,9 +43,8 @@ function expandImports(source: string, options: Options) { const lines = source.split(/\r\n|\r|\n/); let outputCode = options.importHelpers ? ` - const { useUnique } = require('@graphql-tools/webpack-loader-runtime'); - - const unique = useUnique(); + var useUnique = require('@graphql-tools/webpack-loader-runtime').useUnique; + var unique = useUnique(); ` : ` ${uniqueCode} @@ -75,7 +74,7 @@ export default function graphqlLoader(source: string) { } const headerCode = ` - const doc = ${JSON.stringify(doc)}; + var doc = ${JSON.stringify(doc)}; `; let outputCode = ''; diff --git a/packages/webpack-loader/tests/loader.test.ts b/packages/webpack-loader/tests/loader.test.ts index 9ade6c7b55c..3f1d8e8ef81 100644 --- a/packages/webpack-loader/tests/loader.test.ts +++ b/packages/webpack-loader/tests/loader.test.ts @@ -15,7 +15,7 @@ test('basic query', () => { `; const doc = useLoader(docStr, {}); - const docLine = `const doc = ${JSON.stringify(parse(docStr, { noLocation: true }))};`; + const docLine = `var doc = ${JSON.stringify(parse(docStr, { noLocation: true }))};`; const exportLine = `module.exports = doc`; expect(doc).toContain(docLine); @@ -43,7 +43,7 @@ test('basic query with esModules on', () => { esModule: true }); - const docLine = `const doc = ${JSON.stringify(parse(docStr, { noLocation: true }))};`; + const docLine = `var doc = ${JSON.stringify(parse(docStr, { noLocation: true }))};`; const exportLine = `export default doc`; expect(doc).toContain(docLine);