Skip to content

Commit 840c7ce

Browse files
authored
Export FluentResource from fluent (#286)
* Export FluentResource from fluent * Remove the _parse export from fluent
1 parent ec1d42d commit 840c7ce

20 files changed

+43
-25
lines changed

fluent/src/context.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import FluentResource from "./resource";
1414
* context's language. See the documentation of the Fluent syntax for more
1515
* information.
1616
*/
17-
export class FluentBundle {
17+
export default class FluentBundle {
1818

1919
/**
2020
* Create an instance of `FluentBundle`.
@@ -122,10 +122,10 @@ export class FluentBundle {
122122
/**
123123
* Add a translation resource to the context.
124124
*
125-
* The translation resource must be a proper FluentResource
126-
* parsed by `FluentBundle.parseResource`.
125+
* The translation resource must be an instance of FluentResource,
126+
* e.g. parsed by `FluentResource.fromString`.
127127
*
128-
* let res = FluentBundle.parseResource("foo = Foo");
128+
* let res = FluentResource.fromString("foo = Foo");
129129
* bundle.addResource(res);
130130
* bundle.getMessage('foo');
131131
*

fluent/src/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
*
88
*/
99

10-
export { default as _parse } from "./parser";
11-
12-
export { FluentBundle } from "./context";
10+
export { default as FluentBundle } from "./context";
11+
export { default as FluentResource } from "./resource";
1312
export { FluentType, FluentNumber, FluentDateTime } from "./types";
1413

1514
export { ftl } from "./util";

fluent/test/arguments_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { FluentType } from '../src/types';
77
import { ftl } from '../src/util';
88

fluent/test/attributes_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
suite('Attributes', function() {

fluent/test/bomb_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
suite('Reference bombs', function() {

fluent/test/constructor_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import assert from 'assert';
44
import sinon from 'sinon';
55

6-
import { FluentBundle } from '../src/context';
6+
import FluentBundle from '../src/context';
77
import { ftl } from '../src/util';
88

99
suite('FluentBundle constructor', function() {

fluent/test/context_test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
6+
import FluentResource from '../src/resource';
67
import { ftl } from '../src/util';
78

89
suite('Bundle', function() {
@@ -70,6 +71,24 @@ suite('Bundle', function() {
7071
});
7172
});
7273

74+
suite('addResource', function(){
75+
suiteSetup(function() {
76+
bundle = new FluentBundle('en-US', { useIsolating: false });
77+
let resource = FluentResource.fromString(ftl`
78+
foo = Foo
79+
-bar = Bar
80+
`);
81+
bundle.addResource(resource);
82+
});
83+
84+
test('adds messages', function() {
85+
assert.equal(bundle._messages.has('foo'), true);
86+
assert.equal(bundle._terms.has('foo'), false);
87+
assert.equal(bundle._messages.has('-bar'), false);
88+
assert.equal(bundle._terms.has('-bar'), true);
89+
});
90+
});
91+
7392
suite('hasMessage', function(){
7493
suiteSetup(function() {
7594
bundle = new FluentBundle('en-US', { useIsolating: false });

fluent/test/functions_builtin_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
suite('Built-in functions', function() {

fluent/test/functions_runtime_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
suite('Runtime-specific functions', function() {

fluent/test/functions_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
suite('Functions', function() {

fluent/test/isolating_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
// Unicode bidi isolation characters.

fluent/test/patterns_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
suite('Patterns', function(){

fluent/test/primitives_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
suite('Primitives', function() {

fluent/test/select_expressions_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
suite('Select expressions', function() {

fluent/test/transform_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
suite('Transformations', function(){

fluent/test/values_format_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
suite('Formatting values', function(){

fluent/test/values_ref_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import assert from 'assert';
44

5-
import { FluentBundle } from '../src/context';
5+
import FluentBundle from '../src/context';
66
import { ftl } from '../src/util';
77

88
suite('Referencing values', function(){

tools/perf/benchmark.d8.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var resource = FluentSyntax.parse(ftlCode);
1616
times.ftlParseEnd = Date.now();
1717

1818
times.ftlEntriesParseStart = Date.now();
19-
var [entries] = Fluent._parse(ftlCode);
19+
var resource = Fluent.FluentResource.fromString(ftlCode);
2020
times.ftlEntriesParseEnd = Date.now();
2121

2222
var bundle = new Fluent.FluentBundle('en-US');

tools/perf/benchmark.jsshell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var resource = FluentSyntax.parse(ftlCode);
1616
times.ftlParseEnd = dateNow();
1717

1818
times.ftlEntriesParseStart = dateNow();
19-
var [entries] = Fluent._parse(ftlCode);
19+
var resource = Fluent.FluentResource.fromString(ftlCode);
2020
times.ftlEntriesParseEnd = dateNow();
2121

2222
var bundle = new Fluent.FluentBundle('en-US');

tools/perf/benchmark.node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var resource = FluentSyntax.parse(ftlCode);
2020
cumulative.ftlParseEnd = process.hrtime(start);
2121

2222
cumulative.ftlEntriesParseStart = process.hrtime(start);
23-
var [entries] = Fluent._parse(ftlCode);
23+
var resource = Fluent.FluentResource.fromString(ftlCode);
2424
cumulative.ftlEntriesParseEnd = process.hrtime(start);
2525

2626
var bundle = new Fluent.FluentBundle('en-US');

0 commit comments

Comments
 (0)