-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move SVG attribute deprecation warnings into a devtool
In #5590 a new system was introduced for tracking dev-time warnings. This commit uses it for reporting SVG attribute deprecation warnings.
- Loading branch information
Showing
4 changed files
with
83 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/renderers/dom/shared/devtools/ReactDOMSVGDeprecatedAttributeDevtool.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright 2013-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactDOMSVGDeprecatedAttributeDevtool | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var DOMProperty = require('DOMProperty'); | ||
|
||
var warning = require('warning'); | ||
|
||
if (__DEV__) { | ||
var reactProps = { | ||
children: true, | ||
dangerouslySetInnerHTML: true, | ||
key: true, | ||
ref: true, | ||
}; | ||
var warnedSVGAttributes = {}; | ||
|
||
var warnDeprecatedSVGAttribute = function(name) { | ||
if (!DOMProperty.properties.hasOwnProperty(name)) { | ||
return; | ||
} | ||
|
||
if (reactProps.hasOwnProperty(name) && reactProps[name] || | ||
warnedSVGAttributes.hasOwnProperty(name) && warnedSVGAttributes[name]) { | ||
return; | ||
} | ||
|
||
var { attributeName, attributeNamespace } = DOMProperty.properties[name]; | ||
if (attributeNamespace || name === attributeName) { | ||
return; | ||
} | ||
|
||
warning( | ||
false, | ||
'SVG property %s is deprecated. Use the original attribute name ' + | ||
'%s for SVG tags instead.', | ||
name, | ||
attributeName | ||
); | ||
}; | ||
} | ||
|
||
var ReactDOMSVGDeprecatedAttributeDevtool = { | ||
onCreateMarkupForSVGAttribute(name, value) { | ||
warnDeprecatedSVGAttribute(name); | ||
}, | ||
onSetValueForSVGAttribute(node, name, value) { | ||
warnDeprecatedSVGAttribute(name); | ||
}, | ||
}; | ||
|
||
module.exports = ReactDOMSVGDeprecatedAttributeDevtool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters