Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"presets": [
"es2015",
"es2016",
"es2017"
],
"plugins": [
"transform-flow-strip-types"
]
"presets": ["@babel/preset-env"],
"plugins": ["transform-flow-strip-types"]
}
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"node": true,
"es6": true
},
"parser": "babel-eslint",
"parser": "hermes-eslint",
"parserOptions": {
"sourceType": "module"
},
"extends": "eslint:recommended",
"plugins": ["ft-flow"],
"extends": ["eslint:recommended", "plugin:ft-flow/recommended"],
"rules": {
"semi": [2, "always"],
"curly": [2, "multi-line"]
Expand Down
74 changes: 43 additions & 31 deletions __tests__/__snapshots__/dedent-macro-test.js.snap
Original file line number Diff line number Diff line change
@@ -1,76 +1,88 @@
exports[`as a function 1`] = `
"
import dedent from \"../macro\";
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`macros 1. as a function: 1. as a function 1`] = `


import dedent from "../macro";

dedent(\`
some stuff
\`);


↓ ↓ ↓ ↓ ↓ ↓

\"some stuff\";
"
"some stuff";

`;

exports[`as a template string 1`] = `
"
import dedent from \"../macro\";
exports[`macros 2. as a template string: 2. as a template string 1`] = `


import dedent from "../macro";

dedent\`
some stuff
\`;


↓ ↓ ↓ ↓ ↓ ↓

\"some stuff\";
"
"some stuff";

`;

exports[`explicit newline 1`] = `
"
import dedent from \"../macro\";
exports[`macros 3. explicit newline: 3. explicit newline 1`] = `


import dedent from "../macro";

dedent\`
<p>
Hello world!
</p>

\`;


↓ ↓ ↓ ↓ ↓ ↓

\"<p>\\n Hello world!\\n</p>\";
"
"<p>\\n Hello world!\\n</p>";

`;

exports[`expressions 1`] = `
"
import dedent from \"../macro\";
exports[`macros 4. multiple indentations: 4. multiple indentations 1`] = `


import dedent from "../macro";

dedent\`
first line
second
third
first
second
third
\`;


↓ ↓ ↓ ↓ ↓ ↓

\"first line\\n second\\n third\";
"
"first\\n second\\n third";

`;

exports[`multiple indentations 1`] = `
"
import dedent from \"../macro\";
exports[`macros 5. expressions: 5. expressions 1`] = `


import dedent from "../macro";

dedent\`
first
second
third
first line
second
third
\`;


↓ ↓ ↓ ↓ ↓ ↓

\"first\\n second\\n third\";
"
"first line\\n second\\n third";

`;
4 changes: 3 additions & 1 deletion __tests__/__snapshots__/dedent-tests.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`dedent can be used as a function 1`] = `"A test argument."`;

exports[`dedent doesn't strip exlicit newlines 1`] = `
Expand All @@ -24,7 +26,7 @@ exports[`dedent works with blank first line 1`] = `
"Some text that I might want to indent:
* reasons
* fun
That\'s all."
That's all."
`;

exports[`dedent works with escaped tabs for indentation 1`] = `
Expand Down
17 changes: 6 additions & 11 deletions dist/dedent.js
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FWIW I plan on .gitignoreing this file in a next step. No need to check it in.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = dedent;
exports["default"] = dedent;
function dedent(strings) {
// $FlowFixMe: Flow doesn't undestand .raw
var raw = typeof strings === "string" ? [strings] : strings.raw;
Expand All @@ -16,9 +16,8 @@ function dedent(strings) {
.replace(/\\\n[ \t]*/g, "")
// handle escaped backticks
.replace(/\\`/g, "`");

if (i < (arguments.length <= 1 ? 0 : arguments.length - 1)) {
result += arguments.length <= i + 1 ? undefined : arguments[i + 1];
result += i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1];
}
}

Expand All @@ -37,16 +36,12 @@ function dedent(strings) {
}
}
});

if (mindent !== null) {
(function () {
var m = mindent; // appease Flow
result = lines.map(function (l) {
return l[0] === " " || l[0] === "\t" ? l.slice(m) : l;
}).join("\n");
})();
var m = mindent; // appease Flow
result = lines.map(function (l) {
return l[0] === " " || l[0] === "\t" ? l.slice(m) : l;
}).join("\n");
}

return result
// dedent eats leading and trailing whitespace too
.trim()
Expand Down
20 changes: 10 additions & 10 deletions package.json
Copy link
Collaborator Author

@JoshuaKGoldberg JoshuaKGoldberg May 22, 2023

Choose a reason for hiding this comment

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

@cometkim since you authored #32, do you want to review this PR?

(I realize #32 is from 2020; I just don't want to be rude and blow past you in making this in case you're still interested & have time!)

Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
},
"homepage": "https://github.com/dmnd/dedent",
"devDependencies": {
"babel-cli": "^6.22.2",
"babel-eslint": "^7.1.1",
"babel-plugin-macros": "^2.0.0",
"@babel/cli": "^7.21.5",
"@babel/core": "^7.21.8",
"@babel/preset-env": "^7.21.5",
"babel-plugin-macros": "^3.1.0",
"babel-plugin-tester": "^11.0.4",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-plugin-tester": "^5.0.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-es2016": "^6.22.0",
"babel-preset-es2017": "^6.22.0",
"eslint": "^3.14.1",
"flow-bin": "^0.38.0",
"jest": "^18.1.0"
"eslint-plugin-ft-flow": "^2.0.3",
"eslint": "^8.41.0",
"flow-bin": "^0.206.0",
"hermes-eslint": "^0.11.1",
"jest": "^29.5.0"
},
"scripts": {
"build": "babel dedent.js --out-file dist/dedent.js",
Expand Down
Loading