Skip to content

Commit

Permalink
chore: Preserve comments when replacing imports for goog.module format (
Browse files Browse the repository at this point in the history
#1370)

Resolves #1368
  • Loading branch information
lynnmercier authored Oct 2, 2017
1 parent 8dfda54 commit f0b607d
Show file tree
Hide file tree
Showing 32 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/mdc-animation/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-base/component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-base/foundation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-base/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-checkbox/adapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-checkbox/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-checkbox/foundation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-checkbox/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-form-field/adapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-form-field/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-form-field/foundation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-form-field/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-icon-toggle/adapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-icon-toggle/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-icon-toggle/foundation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-icon-toggle/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-menu/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-menu/simple/adapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-menu/simple/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-menu/simple/foundation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-menu/simple/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-radio/adapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-radio/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-radio/foundation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-radio/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-ripple/adapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-ripple/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-ripple/foundation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-ripple/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-ripple/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-selection-control/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @license
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
11 changes: 9 additions & 2 deletions scripts/rewrite-decl-statements-for-closure-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,14 @@ function transform(srcFile, rootDir) {
}

const variableDeclarator = t.variableDeclarator(variableDeclaratorId, callExpression);
path.replaceWith(t.variableDeclaration('const', [variableDeclarator]));
const variableDeclaration = t.variableDeclaration('const', [variableDeclarator]);
// Preserve comments above import statements, since this is most likely the license comment.
if (path.node.comments && path.node.comments.length > 0) {
const commentValue = path.node.comments[0].value;
variableDeclaration.comments = variableDeclaration.comments || [];
variableDeclaration.comments.push({type: 'CommentBlock', value: commentValue});
}
path.replaceWith(variableDeclaration);
},
});

Expand All @@ -156,7 +163,7 @@ function transform(srcFile, rootDir) {
const packageParts = relativePath.replace('mdc-', '').replace('.js', '').split('/');
const packageStr = 'mdc.' + packageParts.join('.').replace('.index', '');

outputCode = 'goog.module(\'' + packageStr + '\')\n' + outputCode;
outputCode = 'goog.module(\'' + packageStr + '\');\n' + outputCode;
fs.writeFileSync(srcFile, outputCode, 'utf8');
console.log(`[rewrite] ${srcFile}`);
}
Expand Down

0 comments on commit f0b607d

Please sign in to comment.