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
264 changes: 6 additions & 258 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,14 @@
"dependencies": {
"@babel/core": "^7.29.0",
"@babel/generator": "^7.29.1",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.29.0",
"@babel/plugin-proposal-export-default-from": "^7.27.1",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.29.5",
"@babel/preset-flow": "^7.27.1",
"@babel/preset-react": "^7.28.5",
"@babel/preset-typescript": "^7.28.5",
"@babel/template": "^7.28.6",
"babel-plugin-ttag": "1.8.16",
"babel-preset-const-enum": "^1.0.0",
"chalk": "^2.4.2",
"cross-spawn": "^7.0.6",
"estree-walker": "^2.0.1",
Expand Down
6 changes: 0 additions & 6 deletions src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ declare module "gettext-parser/lib/shared";
declare module "babel-plugin-ttag";
declare module "@babel/preset-react";
declare module "@babel/preset-env";
declare module "@babel/plugin-proposal-class-properties";
declare module "@babel/plugin-proposal-object-rest-spread";
declare module "@babel/plugin-proposal-export-default-from";
declare module "@babel/plugin-syntax-dynamic-import";
declare module "@babel/plugin-proposal-decorators";
declare module "@babel/preset-typescript";
declare module "@babel/preset-flow";
declare module "@babel/plugin-proposal-optional-chaining";
declare module "@babel/plugin-proposal-nullish-coalescing-operator";
declare module "babel-preset-const-enum";
declare module "magic-string" {
export type SourceMap = any;
}
Expand Down
16 changes: 2 additions & 14 deletions src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,20 @@ import { TransformOptions, ConfigItem } from "@babel/core";
import * as ttagTypes from "./types";

// plugins
import * as classPropPlugin from "@babel/plugin-proposal-class-properties";
import * as restSpreadPlugin from "@babel/plugin-proposal-object-rest-spread";
import * as exportDefaultFromPlugin from "@babel/plugin-proposal-export-default-from";
import * as babelTtagPlugin from "babel-plugin-ttag";
import * as babelDynamicImportPlugin from "@babel/plugin-syntax-dynamic-import";
import * as babelPluginDecorators from "@babel/plugin-proposal-decorators";
import * as optionalChaningPlugin from "@babel/plugin-proposal-optional-chaining";
import * as nullishCoalescingOperatorPlugin from "@babel/plugin-proposal-nullish-coalescing-operator";
import * as presetConstEnumTS from "babel-preset-const-enum";

export const defaultPlugins: ConfigItem[] = [
[babelPluginDecorators, { legacy: true }],
[classPropPlugin, { loose: true }],
restSpreadPlugin,
exportDefaultFromPlugin,
babelDynamicImportPlugin,
optionalChaningPlugin,
nullishCoalescingOperatorPlugin
];

export const defaultPresets: ConfigItem[] = [
presetTS,
presetConstEnumTS,
presetFlow,
[presetEnv, { loose: true, targets: "node 6.5" }],
presetReact
presetReact,
[presetTS, { allowDeclareFields: true }],
];

export function makeBabelConf(ttagOpts: ttagTypes.TtagOpts, cliOpts: ttagTypes.CliOpts ): TransformOptions {
Expand Down
12 changes: 12 additions & 0 deletions tests/commands/__snapshots__/test_extract.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ msgstr \\"\\"
"
`;

exports[`extract from ts with declare 1`] = `
"msgid \\"\\"
msgstr \\"\\"
\\"Content-Type: text/plain; charset=utf-8\\\\n\\"
\\"Plural-Forms: nplurals=2; plural=(n!=1);\\\\n\\"

#: tests/fixtures/tsDeclare.ts:23
msgid \\"hi from a module with typescript declare\\"
msgstr \\"\\"
"
`;

exports[`extract from tsx 1`] = `
"msgid \\"\\"
msgstr \\"\\"
Expand Down
7 changes: 7 additions & 0 deletions tests/commands/test_extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const globalFn = path.resolve(__dirname, "../fixtures/globalFunc.js");
const tsPath = path.resolve(__dirname, "../fixtures/tSParse.ts");
const tsChaning = path.resolve(__dirname, "../fixtures/tsOptionalChaning.ts");
const tsConstEnum = path.resolve(__dirname, "../fixtures/tsConstEnum.ts");
const tsDeclare = path.resolve(__dirname, "../fixtures/tsDeclare.ts");
const tsCoalescing = path.resolve(
__dirname,
"../fixtures/tsNullishCoalescing.ts"
Expand Down Expand Up @@ -132,3 +133,9 @@ test("extract from ts with const enum", () => {
const result = fs.readFileSync(potPath).toString();
expect(result).toMatchSnapshot();
});

test("extract from ts with declare", () => {
execSync(`ts-node src/index.ts extract -o ${potPath} ${tsDeclare}`);
const result = fs.readFileSync(potPath).toString();
expect(result).toMatchSnapshot();
});
23 changes: 23 additions & 0 deletions tests/fixtures/tsDeclare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { t } from "ttag";

declare namespace MyNamespace {
function namespaceFunction(): void;
}

declare function myFunction(): void;
declare const myConst: number;
declare const myLet: number;

class MyClass {
declare myClassField: void;
}

declare class MyClassDeclaration {
method(): void;
}

declare module "hi" {

}

const x = t`hi from a module with typescript declare`