-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b45998
commit 61876ee
Showing
19 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { testB } from './b.mjs'; | ||
|
||
export function testA() { | ||
console.log("testA"); | ||
} | ||
|
||
testB(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let env = {FOO: 'baz'}; | ||
|
||
function setEnv(newEnv) { | ||
console.log('setting env, env.FOO is', newEnv.FOO); | ||
env = newEnv; | ||
} | ||
|
||
export { setEnv, env }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const o = { name5: 1, name6: 1 }; | ||
const array = [1, 1] | ||
|
||
// Exporting declarations | ||
export let name1 = 1, name2 = 1/*, … */; // also var | ||
export const name3 = 1, name4 = 1/*, … */; // also var, let | ||
export function functionName() { return 1 } | ||
export class ClassName { getFoo() { return 1 } } | ||
export function* generatorFunctionName() { return 1 } | ||
export const { name5, name6: bar } = o; | ||
export const [ name7, name8 ] = array; | ||
export async function asyncFunctionName() { return 1 } | ||
export async function* asyncGeneratorFunctionName() { yield 1 } | ||
export const arrowFunction = () => { | ||
return 1; | ||
} | ||
export const asyncArrowFunction = async () => { | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default class { getFoo() { return 1 } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default class ClassName { getFoo() { return 1 } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default [1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'dog' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default function () { return 1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default function functionName() { return 1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default function* () { return 1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default function* generatorFunctionName() { return 1 } |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Export list | ||
const name1 = 1 | ||
const name2 = 1 | ||
const name5 = 1 | ||
const variable1 = 1 | ||
const variable2 = 1 | ||
const variable3 = 1 | ||
const name6 = 1 | ||
export { name1, name2 }; | ||
export { variable1 as name3, variable2 as name4, /* …, */ name5 }; | ||
export { variable3 as "name" }; | ||
export { name6 as default /*, … */ }; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,84 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
import Hook from '../../index.js' | ||
import defaultImportExport from '../fixtures/import-default-export.mjs' | ||
import varDefaultExport from '../fixtures/variable-default-export.mjs' | ||
import a from '../fixtures/export-types/default-expression-array.mjs' | ||
import n from '../fixtures/export-types/default-expression-num.mjs' | ||
import s from '../fixtures/export-types/default-expression-string.mjs' | ||
import fn from '../fixtures/export-types/default-function.mjs' | ||
import cn from '../fixtures/export-types/default-class.mjs' | ||
import gfn from '../fixtures/export-types/default-generator.mjs' | ||
import afn from '../fixtures/export-types/default-function-anon.mjs' | ||
import acn from '../fixtures/export-types/default-class-anon.mjs' | ||
import agfn from '../fixtures/export-types/default-generator-anon.mjs' | ||
import defaultImportExport from '../fixtures/export-types/import-default-export.mjs' | ||
import varDefaultExport from '../fixtures/export-types/variable-default-export.mjs' | ||
import { strictEqual } from 'assert' | ||
|
||
Hook((exports, name) => { | ||
if (name.match(/import-default-export\.m?js/)) { | ||
if (name.match(/default-expression-array\.m?js/)) { | ||
exports.default[0] += 1 | ||
} else if (name.match(/default-expression-num\.m?js/)) { | ||
exports.default += 1 | ||
} | ||
else if (name.match(/default-expression-string\.m?js/)) { | ||
exports.default += 'dawg' | ||
} | ||
else if (name.match(/default-function\.m?js/)) { | ||
const orig = exports.default | ||
exports.default = function () { | ||
return orig() + 1 | ||
} | ||
} else if (name.match(/variable-default-export\.m?js/)) { | ||
} | ||
else if (name.match(/default-class\.m?js/)) { | ||
exports.default.prototype.getFoo = function () { | ||
return 2 | ||
} | ||
} | ||
else if (name.match(/default-generator\.m?js/)) { | ||
const orig2 = exports.default | ||
exports.default = function* () { | ||
return orig2().next().value + 1 | ||
} | ||
} | ||
else if (name.match(/default-function-anon\.m?js/)) { | ||
const orig = exports.default | ||
exports.default = function () { | ||
return orig() + 1 | ||
} | ||
} | ||
else if (name.match(/default-class-anon\.m?js/)) { | ||
exports.default.prototype.getFoo = function () { | ||
return 2 | ||
} | ||
} | ||
else if (name.match(/default-generator-anon\.m?js/)) { | ||
const orig2 = exports.default | ||
exports.default = function* () { | ||
return orig2().next().value + 1 | ||
} | ||
} else if (name.match(/import-default-export\.m?js/)) { | ||
const orig3 = exports.default | ||
exports.default = function () { | ||
return orig3() + 1 | ||
} | ||
} else if (name.match(/variable-default-export\.m?js/)) { | ||
const orig4 = exports.default | ||
exports.default = function () { | ||
return orig2() + 1 | ||
return orig4() + 1 | ||
} | ||
} | ||
}) | ||
|
||
strictEqual(defaultImportExport(), 2) | ||
strictEqual(varDefaultExport(), 2) | ||
strictEqual(varDefaultExport(), 2) | ||
strictEqual(a[0], 2) | ||
strictEqual(fn(), 2) | ||
strictEqual(new cn().getFoo(), 2) | ||
strictEqual(gfn().next().value, 2) | ||
strictEqual(afn(), 2) | ||
strictEqual(new acn().getFoo(), 2) | ||
strictEqual(agfn().next().value, 2) | ||
strictEqual(n, 2) | ||
strictEqual(s, 'dogdawg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
import { spawn } from 'child_process' | ||
import { strictEqual } from 'assert' | ||
|
||
const nodeProcess = spawn('node', [ | ||
'--loader', | ||
'./hook.mjs', | ||
'./test/fixtures/a.mjs' | ||
]) | ||
|
||
// expected output is 'testB\ntestA' but the actual output of this test is '' because | ||
// the hook fails when running against files with cylical dependencies | ||
const expectedOutput = 'testB\ntestA' | ||
const actualOutput = '' | ||
let stdout = '' | ||
let stderr = '' | ||
|
||
nodeProcess.stdout.on('data', (data) => { | ||
stdout += data.toString() | ||
}); | ||
|
||
nodeProcess.stderr.on('data', (data) => { | ||
stderr += data.toString() | ||
}); | ||
|
||
nodeProcess.on('close', (code) => { | ||
strictEqual(stderr, '', 'There should be no errors on stderr') | ||
strictEqual(stdout.trim(), actualOutput, 'The stdout should match the expected output') | ||
}); |