Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Migrate from goog.module.declareNamespace to goog.declareModuleId. We…
Browse files Browse the repository at this point in the history
…'re just renaming the function to make it clearer. For now both functions are supported until goog.module.declareNamespace is no longer used.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=214629511
  • Loading branch information
johnplaisted authored and Nick Reid committed Sep 26, 2018
1 parent dcd8ff3 commit 18483fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion closure-deps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const goog = parser.parseText('/** @provideGoog */', '/base.js').dependency;

const firstFile = parser.parseText(
`
goog.module.declareNamespace('first.module');
goog.declareModuleId('first.module');
export const FOO = 'foo';
`, "/first.js").dependency;

Expand Down
2 changes: 1 addition & 1 deletion closure-deps/spec/tests/depfile_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('depfile', function() {
`{'lang': 'es6', 'module': 'es6'});\n`);
});

it('declareNamespace', function() {
it('declareModuleId', function() {
const d = new depGraph.Dependency(
depGraph.DependencyType.ES6_MODULE, PATH_TO_CLOSURE + 'example.js',
['my.es6'], []);
Expand Down
30 changes: 14 additions & 16 deletions closure-deps/spec/tests/parser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,18 @@ describe('parse', function() {
});
});

describe('declareNamespace', function() {
describe('declareModuleId', function() {
it('first then export', function() {
const dep = parseNoErrors(
'goog.module.declareNamespace("my.es6");', 'export {};');
const dep =
parseNoErrors('goog.declareModuleId("my.es6");', 'export {};');

expect(dep.type).toEqual(
depGraph.DependencyType.ES6_MODULE);
expect(dep.type).toEqual(depGraph.DependencyType.ES6_MODULE);
expect(dep.closureSymbols).toEqual(['my.es6']);
});

it('after export', function() {
const dep = parseNoErrors(
'export {};', 'goog.module.declareNamespace("my.es6");');
const dep =
parseNoErrors('export {};', 'goog.declareModuleId("my.es6");');

expect(dep.type).toEqual(
depGraph.DependencyType.ES6_MODULE);
Expand All @@ -273,10 +272,9 @@ describe('parse', function() {

it('twice is error', function() {
hasFatalParseError(
'goog.module.declareNamespace can only be called once per ES6 ' +
'module.',
'export {};', 'goog.module.declareNamespace("my.es6");',
'goog.module.declareNamespace("my.es6_0");');
'goog.declareModuleId can only be called once per ES6 module.',
'export {};', 'goog.declareModuleId("my.es6");',
'goog.declareModuleId("my.es6_0");');
});
});
});
Expand All @@ -291,17 +289,17 @@ describe('parse', function() {
expect(dep.type).toEqual(depGraph.DependencyType.SCRIPT);
});

describe('declareNamespace is error in', function() {
describe('declareModuleId is error in', function() {
it('goog.provide', function() {
hasFatalParseError(
'goog.module.declareNamespace can only be called within ES6 modules.',
'goog.provide("a.b");', 'goog.module.declareNamespace("ex");');
'goog.declareModuleId can only be called within ES6 modules.',
'goog.provide("a.b");', 'goog.declareModuleId("ex");');
});

it('goog.module', function() {
hasFatalParseError(
'goog.module.declareNamespace can only be called within ES6 modules.',
'goog.module("a.b");', 'goog.module.declareNamespace("ex");');
'goog.declareModuleId can only be called within ES6 modules.',
'goog.module("a.b");', 'goog.declareModuleId("ex");');
});
});

Expand Down
12 changes: 7 additions & 5 deletions closure-deps/spec/tests/readme_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ describe('examples in README', function() {
});

it('es6 modules', function() {
const firstFile = parser.parseText(
lines(
'goog.module.declareNamespace(\'first.module\');',
'export const FOO = \'foo\';'),
'/first.js').dependency;
const firstFile = parser
.parseText(
lines(
'goog.declareModuleId(\'first.module\');',
'export const FOO = \'foo\';'),
'/first.js')
.dependency;

const secondFile =
parser.parseText('import {FOO} from "./first.js";', '/second.js')
Expand Down

0 comments on commit 18483fa

Please sign in to comment.